From d38f9e3c3e680fb21d0dcd6e94d486bbadf8b6e9 Mon Sep 17 00:00:00 2001 From: "1992414357@qq.com" <1992414357@qq.com> Date: Mon, 9 Jun 2025 10:26:17 +0800 Subject: 修改了 Idea 环境下的运行配置. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/convert_utils.rs | 10 --------- src/file_system_utils.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 10 deletions(-) delete mode 100644 src/convert_utils.rs create mode 100644 src/file_system_utils.rs (limited to 'src') diff --git a/src/convert_utils.rs b/src/convert_utils.rs deleted file mode 100644 index fccd01e..0000000 --- a/src/convert_utils.rs +++ /dev/null @@ -1,10 +0,0 @@ -use std::collections::VecDeque; - -pub fn convert_deque_to_vec (deque: &VecDeque) -> Vec { - let vec_deque_ref = deque; - let mut vec = Vec::new(); - for item in vec_deque_ref { - vec.push(item.clone()) - } - vec -} \ No newline at end of file diff --git a/src/file_system_utils.rs b/src/file_system_utils.rs new file mode 100644 index 0000000..3296324 --- /dev/null +++ b/src/file_system_utils.rs @@ -0,0 +1,54 @@ +use std::io::Error; +use std::path::PathBuf; +use std::process::Command; + +pub fn open_in_explorer(path: PathBuf) -> Result<(), Error> { + let absolute_path = if path.is_relative() { + std::env::current_dir()?.join(path) + } else { + path + }; + + let absolute_path = absolute_path.canonicalize().unwrap_or(absolute_path); + + if !absolute_path.exists() { + return Err(Error::new( + std::io::ErrorKind::NotFound, + format!("Path does not exist: {}", absolute_path.display()) + )); + } + + if cfg!(target_os = "windows") { + if absolute_path.is_file() { + absolute_path.parent() + .ok_or_else(|| Error::new( + std::io::ErrorKind::InvalidInput, + "File has no parent directory" + ))?; + + Command::new("explorer") + .args(&["/select,", absolute_path.to_str().unwrap()]) + .spawn()?; + } else { + Command::new("explorer") + .arg(absolute_path.to_str().unwrap()) + .spawn()?; + } + } else if cfg!(target_os = "macos") { + if absolute_path.is_file() { + Command::new("open") + .args(&["-R", absolute_path.to_str().unwrap()]) + .spawn()?; + } else { + Command::new("open") + .arg(absolute_path.to_str().unwrap()) + .spawn()?; + } + } else { + Command::new("xdg-open") + .arg(absolute_path.to_str().unwrap()) + .spawn()?; + } + + Ok(()) +} \ No newline at end of file -- cgit