From a46acd2ff8b3ee4eb83cf413e3926c7a3416edfd Mon Sep 17 00:00:00 2001 From: Alireza Adli Date: Mon, 26 Feb 2024 11:22:01 -0500 Subject: [PATCH] Add find shp files to the basic functions --- services_scripts/basic_functions.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/services_scripts/basic_functions.py b/services_scripts/basic_functions.py index a991301..9fb9536 100644 --- a/services_scripts/basic_functions.py +++ b/services_scripts/basic_functions.py @@ -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}") \ No newline at end of file + 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