diff options
| author | 1992414357@qq.com <1992414357@qq.com> | 2025-06-09 10:26:17 +0800 |
|---|---|---|
| committer | 1992414357@qq.com <1992414357@qq.com> | 2025-06-09 10:26:17 +0800 |
| commit | d38f9e3c3e680fb21d0dcd6e94d486bbadf8b6e9 (patch) | |
| tree | 91fde277cb5346a4d9c4141d17ba84963eec1088 /src | |
| parent | 7b68281155ea7bc2f5840b921f4a2f5ab7b8ff68 (diff) | |
修改了 Idea 环境下的运行配置.
Diffstat (limited to 'src')
| -rw-r--r-- | src/convert_utils.rs | 10 | ||||
| -rw-r--r-- | src/file_system_utils.rs | 54 |
2 files changed, 54 insertions, 10 deletions
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 <V: Clone>(deque: &VecDeque<V>) -> Vec<V> { - 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 |
