Skip to content

Commit

Permalink
fix - folders that starts with the same name identified as subfolder …
Browse files Browse the repository at this point in the history
…where it is not. for example ["C:\\Users\\user\\Desktop\\folder1", "C:\\Users\\user\\Desktop\\folder11"]
  • Loading branch information
niradar committed Jul 20, 2024
1 parent 20ed00d commit d8c31b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion duplicate_files_in_folders/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def any_is_subfolder_of(folders: List[str]) -> Tuple[bool, List[Tuple[str, str]]
subfolder_pairs = []
for i in range(len(folders)):
for j in range(len(folders)):
if i != j and folders[i].startswith(folders[j]):
if i != j and (folders[i].startswith(folders[j] + os.sep) or folders[i] == folders[j]):
subfolder_pairs.append((folders[i], folders[j]))
return bool(subfolder_pairs), subfolder_pairs

Expand Down
5 changes: 5 additions & 0 deletions tests/test_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ def test_file_manager_any_is_subfolder_of():
"C:\\Users\\user\\Desktop\\folder3"])
assert is_subfolder is False

# test case 9: one folder starts with another
is_subfolder, relationships = FileManager.any_is_subfolder_of(
["C:\\Users\\user\\Desktop\\folder1", "C:\\Users\\user\\Desktop\\folder11"])
assert is_subfolder is False


def test_file_manager_is_allowed_path(setup_teardown):
scan_dir, reference_dir, move_to_dir, common_args = setup_teardown
Expand Down

0 comments on commit d8c31b3

Please sign in to comment.