-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileExplorer.py
More file actions
22 lines (20 loc) · 857 Bytes
/
FileExplorer.py
File metadata and controls
22 lines (20 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
def explore_directories(root_directory):
try:
# List all the entries in the directory
entries = os.listdir(root_directory)
for entry in entries:
path = os.path.join(root_directory, entry)
if os.path.isdir(path):
print(path)
# Recursively explore the sub-directory
explore_directories(path)
except PermissionError:
# Handle the case where the program doesn't have permission to access a directory
print(f"Permission denied: {root_directory}")
except FileNotFoundError:
# Handle the case where a directory was not found
print(f"Directory not found: {root_directory}")
# Example usage
root_directory = "Desktop" # Replace with the root directory path you want to explore
explore_directories(root_directory)