Skip to content

Commit 597ee2b

Browse files
Update python_folders_files.py
1 parent bfa6904 commit 597ee2b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
3+
def count_and_list_folders(path):
4+
folder_count = 0
5+
folder_list = []
6+
7+
for root, dirs, files in os.walk(path):
8+
for dir in dirs:
9+
folder_count += 1
10+
folder_list.append(os.path.join(root, dir))
11+
12+
return folder_count, folder_list
13+
14+
# Provide the path to the XYZ folder
15+
folder_path = '/path/to/XYZ'
16+
17+
count, folders = count_and_list_folders(folder_path)
18+
19+
print("Number of subfolders:", count)
20+
print("List of subfolders:")
21+
for folder in folders:
22+
print(folder)

0 commit comments

Comments
 (0)