File size: 1,108 Bytes
fd75f40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
import os, csv


def get_directory_names(root_path):
    directory_names = []
    
    # Check if the provided path exists
    if not os.path.exists(root_path):
        print(f"The path {root_path} does not exist.")
        return directory_names
    
    # Iterate through the items in the root path
    for item in os.listdir(root_path):
        item_path = os.path.join(root_path, item)
        # Check if the item is a directory
        if os.path.isdir(item_path):
            directory_names.append(item)
    
    return directory_names

def save_to_csv(directory_names, filename):
    with open(filename, 'w', newline='') as csvfile:
        writer = csv.writer(csvfile)
        # writer.writerow(['Pattern Names'])  # Header
        for name in directory_names:
            writer.writerow([name])
    print(f"Pattern names have been saved to {filename}")

# Example usage
root_directory = "patterns"
output_file = "patterns.csv"

directories = get_directory_names(root_directory)
save_to_csv(directories, output_file)

print("List of directories:")
for directory in directories:
    print(directory)