Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
cqb13 committed Jan 8, 2024
1 parent 15a70d3 commit 02d16c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn display_tree(
for (i, directory) in tree.directories.iter().enumerate() {
let directory_display = format!(
"{} {} {}",
directory.name,
directory.clean_name,
if *show_file_counts_in_directories {
let file_count = directory.file_count;
if file_count > 0 {
Expand Down
21 changes: 18 additions & 3 deletions src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct DirectoryObject {
pub directories: Vec<DirectoryObject>,
pub files: Vec<FileObject>,
pub name: String,
pub clean_name: String,
pub path: String,
pub size: u64,
pub size_string: String,
Expand All @@ -20,6 +21,7 @@ impl DirectoryObject {
directories: Vec::new(),
files: Vec::new(),
name: name.to_string(),
clean_name: String::new(),
path: path.to_string(),
size: 0,
size_string: String::new(),
Expand All @@ -31,6 +33,10 @@ impl DirectoryObject {
self.directories.push(directory);
}

fn set_directory_name(&mut self, name: &String) {
self.clean_name = name.to_string();
}

fn add_file(&mut self, file: FileObject) {
self.files.push(file);
}
Expand Down Expand Up @@ -72,13 +78,14 @@ pub fn scan(start_dir_path: &String, os: &OS) -> DirectoryObject {
let ignored_directories: Vec<&str> = ignored_directories_setting.value.split(",").collect();
let ignored_files: Vec<&str> = ignored_files_setting.value.split(",").collect();

create_tree(start_dir_path, &ignored_directories, &ignored_files)
create_tree(start_dir_path, &ignored_directories, &ignored_files, os)
}

fn create_tree(
start_dir_path: &String,
ignored_directories: &Vec<&str>,
ignored_files: &Vec<&str>,
os: &OS,
) -> DirectoryObject {
let mut directory_stack: Vec<String> = Vec::new();

Expand Down Expand Up @@ -106,10 +113,18 @@ fn create_tree(
.to_string();

if entry_path.is_dir() {
if ignored_directories.contains(&entry_name.as_str()) {

let directory_name = match os {
OS::Windows => entry_name.split("\\").last().unwrap().to_string(),
OS::Mac => entry_name,
};

if ignored_directories.contains(&directory_name.as_str()) {
continue;
}

// add directory name as clean name in directory obj

directory_stack.push(entry_path.to_str().unwrap().to_string());
continue;
} else {
Expand Down Expand Up @@ -150,7 +165,7 @@ fn create_tree(
while !directory_stack.is_empty() {
let current_dir_path = directory_stack.pop().unwrap();

let sub_dir_tree = create_tree(&current_dir_path, ignored_directories, ignored_files);
let sub_dir_tree = create_tree(&current_dir_path, ignored_directories, ignored_files, &os);

tree.add_directory(sub_dir_tree);
}
Expand Down

0 comments on commit 02d16c5

Please sign in to comment.