33import shutil
44
55
6+ def check_recursive (library_path ):
7+ dupe_folders = []
8+ for (root , dirs , files ) in os .walk (library_path , topdown = True ):
9+ for dir in dirs :
10+ full_directory = os .path .join (root ,dir )
11+ # if current_depth > previous_depth and os.path.basename(os.path.normpath(full_directory)) == previous_root_end_folder:
12+ if os .path .basename (os .path .normpath (root )) == os .path .basename (os .path .normpath (full_directory )):
13+ log_to_ui ("WARNING: Folder appears to have been placed inside itself:" )
14+ log_to_ui (f"Current full path: { full_directory } " )
15+
16+ # FIX #
17+ # Note the top-level folder
18+ # top_folder = root
19+ dupe_folder_name = os .path .basename (os .path .normpath (root ))
20+
21+ # Walk from this folder to find out how many matryoshka folders we have
22+ for (root2 , dirs2 , files2 ) in os .walk (root , topdown = True ):
23+ # Iterate over the directories for this level/root
24+ for d in dirs2 :
25+ full_dir_path = os .path .join (root2 ,d )
26+ # Mark dupe folders with the same name as the current ("parent") folder
27+ if os .path .basename (os .path .normpath (d )) == dupe_folder_name :
28+ log_to_ui (f"Nested folder found:\n { full_dir_path } " )
29+
30+
31+
632def fix_recursive (library_path ):
733 dupe_folders = []
834 for (root , dirs , files ) in os .walk (library_path , topdown = True ):
@@ -81,13 +107,20 @@ def fix_recursive(library_path):
81107 return True
82108
83109
84- def check (library_path ):
110+ def check (library_path , fix_folders ):
85111 complete = False
86112 counter = 1
87- while not complete :
88- log_to_ui (f"Checking { library_path } for recursive folders, iteration { counter } -------------------------------------------------------" )
89- complete = fix_recursive (library_path )
90- counter += 1
91113
92- log_to_ui ("Done fixing recursive folders!" )
114+ if fix_folders :
115+ while not complete :
116+ log_to_ui (f"Checking { library_path } for recursive folders, iteration { counter } -------------------------------------------------------" )
117+ complete = fix_recursive (library_path )
118+ counter += 1
119+ log_to_ui ("Done fixing recursive folders!" )
120+ else :
121+ check_recursive (library_path )
122+ log_to_ui ("Done checkin recursive folders!" )
123+ return True
124+
125+
93126
0 commit comments