使用 Rust,打开文件上的资源管理器

ANi*_*120 5 windows macos rust

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

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

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

WBu*_*uck 7

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

苹果系统

use std::process::Command;

fn main( ) {
    println!( "Opening" );
    Command::new( "open" )
        .arg( "." ) // <- Specify the directory you'd like to open.
        .spawn( )
        .unwrap( );
}
Run Code Online (Sandbox Code Playgroud)

视窗

use std::process::Command;

fn main( ) {
    println!( "Opening" );
    Command::new( "explorer" )
        .arg( "." ) // <- Specify the directory you'd like to open.
        .spawn( )
        .unwrap( );
}
Run Code Online (Sandbox Code Playgroud)

编辑:

根据@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( );
}
Run Code Online (Sandbox Code Playgroud)

  • 在 Linux 上,您可以使用 `xdg-open` (2认同)