1

If one wanted to show a file in a File Explorer or use the similar "Reveal in Finder" feature found on OSX, how could you do that in rust? Is there a crate that could help?

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

I'm looking for something similar to this python solution.

ANimator120
  • 1,409
  • 1
  • 7
  • 26

1 Answers1

5

You can use Command to open the finder process.

macOS

use std::process::Command;

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

Windows

use std::process::Command;

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

EDIT:

As per @hellow's comment.

Linux

use std::process::Command;

fn main( ) {
    println!( "Opening" );
    Command::new( "xdg-open" )
        .arg( "." ) // <- Specify the directory you'd like to open.
        .spawn( )
        .unwrap( );
}
WBuck
  • 4,264
  • 2
  • 22
  • 30