【问题标题】:With Rust, Open Explorer on a File使用 Rust,在文件上打开资源管理器
【发布时间】:2021-06-03 17:52:07
【问题描述】:

如果想在文件资源管理器中显示文件或使用 OSX 上类似的“在 Finder 中显示”功能,您如何在 rust 中做到这一点?有没有可以帮忙的板条箱?

fn main(){
   reveal_file("tmp/my_file.jpg")
   //would bring up the file in a File Explorer Window
}

我正在寻找类似于this python 的解决方案。

【问题讨论】:

    标签: windows macos rust


    【解决方案1】:

    您可以使用Command打开finder进程。

    macOS

    use std::process::Command;
    
    fn main( ) {
        println!( "Opening" );
        Command::new( "open" )
            .arg( "." ) // <- Specify the directory you'd like to open.
            .spawn( )
            .unwrap( );
    }
    

    窗口

    use std::process::Command;
    
    fn main( ) {
        println!( "Opening" );
        Command::new( "explorer" )
            .arg( "." ) // <- Specify the directory you'd like to open.
            .spawn( )
            .unwrap( );
    }
    

    编辑:

    根据@hellow 的评论。

    Linux

    use std::process::Command;
    
    fn main( ) {
        println!( "Opening" );
        Command::new( "xdg-open" )
            .arg( "." ) // <- Specify the directory you'd like to open.
            .spawn( )
            .unwrap( );
    }
    

    【讨论】:

    • 我认为您提供的链接已损坏
    • @ANimator120 已修复。我还在Windows 上添加了如何操作(在重新阅读您的问题后,我认为这就是您想要的)
    • 在Linux上你可以使用xdg-open
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多