Added empty folder deletion

This commit is contained in:
justine 2024-11-17 12:56:48 +01:00
parent 022ca14a00
commit 7d684dec51
2 changed files with 12 additions and 1 deletions

View File

@ -13,3 +13,5 @@ pip install -r requirements.txt
``` ```
Take a look at the configuration section inside the script and then launch it. Take a look at the configuration section inside the script and then launch it.
The script will create all destination folders, sort the pictures, and delete empty destination folders in the end.

View File

@ -18,6 +18,13 @@ def pics_list(path:os.path):
def file_move(file, dest): def file_move(file, dest):
shutil.move(file, dest) shutil.move(file, dest)
def delete_empty_folders(rootdir):
folders = [f.path for f in os.scandir(rootdir) if f.is_dir()]
for folder in folders:
if not os.listdir(folder):
print(f"{folder} is empty and will be deleted")
os.rmdir(folder)
def main(): def main():
#------------------ CONFIG START #------------------ CONFIG START
@ -100,6 +107,8 @@ def main():
dest_folder = foldersd dest_folder = foldersd
print(f"{f} moved to {rootdir}{dest_folder}") print(f"{f} moved to {rootdir}{dest_folder}")
delete_empty_folders(rootdir)
print("Done, Sayonara") print("Done, Sayonara")
if __name__ == "__main__": if __name__ == "__main__":