簡體   English   中英

使用 Rust,在文件上打開資源管理器

[英]With Rust, Open Explorer on a File

如果想在文件資源管理器中顯示文件或使用 OSX 上類似的“在 Finder 中顯示”功能,您如何在 rust 中做到這一點? 有沒有可以提供幫助的板條箱?

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

我正在尋找類似於python 解決方案的東西。

您可以使用命令打開查找器進程。

蘋果系統

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( );
}

編輯:

根據@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( );
}

將此添加到您的 Cargo.toml

[dependencies]
open = "3"

......並使用......打開一些東西

open::that(".");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM