首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Rust在文件上打开资源管理器

使用Rust在文件上打开资源管理器
EN

Stack Overflow用户
提问于 2021-03-05 10:35:36
回答 1查看 409关注 0票数 0

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

代码语言:javascript
复制
fn main(){
   reveal_file("tmp/my_file.jpg")
   //would bring up the file in a File Explorer Window
}

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-05 11:25:48

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

macOS

代码语言:javascript
复制
use std::process::Command;

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

视窗

代码语言:javascript
复制
use std::process::Command;

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

编辑:

根据@hellow的评论。

Linux

代码语言:javascript
复制
use std::process::Command;

fn main( ) {
    println!( "Opening" );
    Command::new( "xdg-open" )
        .arg( "." ) // <- Specify the directory you'd like to open.
        .spawn( )
        .unwrap( );
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66485945

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档