added get_subdirectories function
This commit is contained in:
parent
a80d99f871
commit
bc94aad72d
|
|
@ -15,6 +15,13 @@ def append_to_folder_name(folder_path, suffix):
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(f"Error: Folder '{folder_path}' not found.")
|
print(f"Error: Folder '{folder_path}' not found.")
|
||||||
|
|
||||||
|
def get_subdirectories(folder_path):
|
||||||
|
subdirectories = []
|
||||||
|
for root, dirs, files in os.walk(folder_path):
|
||||||
|
for dir_name in dirs:
|
||||||
|
subdirectories.append(os.path.join(root, dir_name))
|
||||||
|
return subdirectories
|
||||||
|
|
||||||
def count_subdirectories(directory):
|
def count_subdirectories(directory):
|
||||||
subdirectory_count = 0
|
subdirectory_count = 0
|
||||||
for _, dirnames, _ in os.walk(directory):
|
for _, dirnames, _ in os.walk(directory):
|
||||||
|
|
@ -24,8 +31,8 @@ def count_subdirectories(directory):
|
||||||
def count_folder_files(folder_path):
|
def count_folder_files(folder_path):
|
||||||
try:
|
try:
|
||||||
# If no subfolders exist, return the number of files in the folder
|
# If no subfolders exist, return the number of files in the folder
|
||||||
subdirectories = count_subdirectories(folder_path)
|
num_subdirectories = count_subdirectories(folder_path)
|
||||||
if subdirectories == 0:
|
if num_subdirectories == 0:
|
||||||
|
|
||||||
# Count the number of files in the folder
|
# Count the number of files in the folder
|
||||||
file_count = sum(1 for entry in os.scandir(folder_path) if entry.is_file())
|
file_count = sum(1 for entry in os.scandir(folder_path) if entry.is_file())
|
||||||
|
|
@ -33,7 +40,8 @@ def count_folder_files(folder_path):
|
||||||
return file_count
|
return file_count
|
||||||
# If subdirectories do exist, return the number of files in each subdirectory then this directory
|
# If subdirectories do exist, return the number of files in each subdirectory then this directory
|
||||||
else:
|
else:
|
||||||
print(">0")
|
subdirectories = get_subdirectories(folder_path)
|
||||||
|
print(subdirectories)
|
||||||
|
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user