Here's the function
def cleanup_dir(rootPath):
pattern_compiled = '*.pyc'
pattern_decompiled = '*.py'
for root, subdirs, files in os.walk(rootPath):
for filename_compiled in fnmatch.filter(files, pattern_compiled):
fc = str(os.path.join(root, filename_compiled))
#print(os.path.join(root, os.sep, "ORIGINALS" , filename_compiled))
#print(f'{root}{os.sep}ORIGINALS{os.sep}{filename}')
try:
shutil.move(fc, f'{root}{os.sep}ORIGINALS{os.sep}{filename_compiled}')
print("Moved %s to .\DECOMPILE\ORIGINALS successfully!" % fc)
except Exception as ex:
print("FAILED to move file %s" % fc)
for filename_decompiled in fnmatch.filter(files, pattern_decompiled):
fd = str(os.path.join(root, filename_decompiled))
try:
shutil.move(fd, f".\Snippets{os.sep}{filename_decompiled}")
print("Moved %s to .\Snippets successfully!" % fc)
except Exception as ex:
print("FAILED to move file %s" %fd) ```
...and here is the output:
Moved .\DECOMPILE\add_to_tuning.pyc to .\DECOMPILE\ORIGINALS successfully!
Moved .\DECOMPILE\detection.pyc to .\DECOMPILE\ORIGINALS successfully!
Moved .\DECOMPILE\injector.pyc to .\DECOMPILE\ORIGINALS successfully!
Moved .\DECOMPILE\snippet.pyc to .\DECOMPILE\ORIGINALS successfully!
Moved .\DECOMPILE\version.pyc to .\DECOMPILE\ORIGINALS successfully!
FAILED to move file .\DECOMPILE\ORIGINALS\add_to_tuning.pyc
FAILED to move file .\DECOMPILE\ORIGINALS\detection.pyc
FAILED to move file .\DECOMPILE\ORIGINALS\injector.pyc
FAILED to move file .\DECOMPILE\ORIGINALS\snippet.pyc
FAILED to move file .\DECOMPILE\ORIGINALS\version.pyc
os.path.join() ignoring first arg "root". commented everything below print():
\ORIGINALS\add_to_tuning.pyc
\ORIGINALS\detection.pyc
\ORIGINALS\injector.pyc
\ORIGINALS\snippet.pyc
\ORIGINALS\version.pyc