SoundHarvest / polish_dataset.py
0x22almostEvil's picture
Upload 5 files
7beabae
import os
import shutil
main_directory = "dataset"
deleted_folders = 0
remaining_folders = 0
for folder_name in os.listdir(main_directory):
folder_path = os.path.join(main_directory, folder_name)
if os.path.isdir(folder_path):
subfolders = os.listdir(folder_path)
if len(subfolders) == 1 and subfolders[0] == "unmatched" and os.path.isdir(os.path.join(folder_path, "unmatched")):
print(f"Content of folder {folder_name}:")
for item in os.listdir(folder_path):
print(f"- {item}")
print(f"It's bad sample. Deleting folder: {folder_name}")
shutil.rmtree(folder_path)
deleted_folders += 1
else:
print(f"Content of folder {folder_name}:")
for item in os.listdir(folder_path):
print(f"- {item}")
print(f"It's good sample #{folder_name}. Keeping.")
remaining_folders += 1
# Display the results
print(f"Deleted {deleted_folders} empty folders.")
print(f"Remaining folders: {remaining_folders}")