Reputation: 3421
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.
Upvotes: 6
Views: 4518
Reputation: 4383
Add this to your Cargo.toml
[dependencies]
open = "3"
…and open something using…
open::that(".");
Upvotes: 4
Reputation: 5503
You can use Command to open the finder process.
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( );
}
EDIT:
As per @hellow's comment.
use std::process::Command;
fn main( ) {
println!( "Opening" );
Command::new( "xdg-open" )
.arg( "." ) // <- Specify the directory you'd like to open.
.spawn( )
.unwrap( );
}
Upvotes: 8