Add find shp files to the basic functions

This commit is contained in:
Alireza Adli 2024-02-26 11:22:01 -05:00
parent c5aade8853
commit a46acd2ff8

View File

@ -1,4 +1,4 @@
import os
import os, glob
def create_folders(directory, num_folders):
@ -18,4 +18,15 @@ def create_folders(directory, num_folders):
folder_name = f"layer_{i}"
folder_path = os.path.join(directory, folder_name)
os.makedirs(folder_path)
print(f"Created folder: {folder_path}")
print(f"Created folder: {folder_path}")
# In a folder (including several sub folders) this function extract
# .shp files from each subfolder
def find_shp_files(root_folder):
shp_files = []
for foldername, _, _ in sorted(os.walk(root_folder)): # Sort folders alphabetically
for filename in sorted(glob.glob(os.path.join(foldername, '*.shp'))):
new_file_name = filename.replace('\\', r'/')
shp_files.append(new_file_name)
return shp_files