summaryrefslogtreecommitdiffstats
path: root/src/utils/path.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-11-05 22:00:53 +0800
committerGitHub <noreply@github.com>2024-11-05 22:00:53 +0800
commit931d7e0b201d2c1c51801c3141509239a4c7a2b2 (patch)
treed17fc1493743d36c346652a4b299f840246f3c95 /src/utils/path.rs
parent42deaa082fe026b955f1bc11b5168a2309aad99b (diff)
downloadaichat-931d7e0b201d2c1c51801c3141509239a4c7a2b2.tar.gz
feat: `.agent` accepts session name (#970)
Diffstat (limited to 'src/utils/path.rs')
-rw-r--r--src/utils/path.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/utils/path.rs b/src/utils/path.rs
index a8534fb..b0a5614 100644
--- a/src/utils/path.rs
+++ b/src/utils/path.rs
@@ -42,6 +42,27 @@ pub async fn expand_glob_paths<T: AsRef<str>>(paths: &[T]) -> Result<Vec<String>
Ok(new_paths)
}
+pub fn list_file_names<T: AsRef<Path>>(dir: Option<T>, ext: &str) -> Vec<String> {
+ let dir = match dir {
+ Some(v) => v,
+ None => return vec![],
+ };
+ match std::fs::read_dir(dir) {
+ Ok(rd) => {
+ let mut names = vec![];
+ for entry in rd.flatten() {
+ let name = entry.file_name();
+ if let Some(name) = name.to_string_lossy().strip_suffix(ext) {
+ names.push(name.to_string());
+ }
+ }
+ names.sort_unstable();
+ names
+ }
+ Err(_) => vec![],
+ }
+}
+
pub fn get_patch_extension(path: &str) -> Option<String> {
Path::new(&path)
.extension()