如果有人想要在文件资源管理器中显示文件,或者使用OSX上类似的“在Finder中显示”功能,你如何在rust中做到这一点?有没有板条箱可以帮上忙?
fn main(){
reveal_file("tmp/my_file.jpg")
//would bring up the file in a File Explorer Window
}我正在寻找类似于this python的解决方案。
发布于 2021-03-05 11:25:48
您可以使用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( );
}https://stackoverflow.com/questions/66485945
复制相似问题