File size: 1,067 Bytes
7beabae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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}")