From 4864bda42edc913a2fcdc9fd7745cb8ec713da10 Mon Sep 17 00:00:00 2001 From: sean-eagles <112004392+sean-eagles@users.noreply.github.com> Date: Fri, 12 Jan 2024 10:34:52 -0500 Subject: [PATCH] Added file via upload Search through one directory and all associated subdirectories to find all shapefiles. (Similar will be done for Feature Classes in GDBs) --- ...inDirectoryAndSubDirectories_5th_option.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 ListAllShapefiles_inDirectoryAndSubDirectories_5th_option.py diff --git a/ListAllShapefiles_inDirectoryAndSubDirectories_5th_option.py b/ListAllShapefiles_inDirectoryAndSubDirectories_5th_option.py new file mode 100644 index 0000000..c70a5a4 --- /dev/null +++ b/ListAllShapefiles_inDirectoryAndSubDirectories_5th_option.py @@ -0,0 +1,34 @@ +#------------------------------------------------------------------------------- +# Name: module1 +# Purpose: +# +# Author: seagles +# +# Created: 11-01-2024 +# Copyright: (c) seagles 2024 +# Licence: +#------------------------------------------------------------------------------- + +import os + +path = os.getcwd() + +print path + " = PATH" + +if __name__ == "__main__": + List_Files = [] + for (root,dirs,files) in os.walk(path, topdown=True): + print (root) + #print (dirs) + #print (files) + files = os.listdir(root) + files = [f for f in files if f.lower().endswith('.shp')] + if len(files)==0: + print("there are no files ending with .shp in your folder") + else: + print('There are {} shapefiles in your folder'.format(len(files))) + for f in files: + print root + "\\" + f + List_Files.append(root + "\\" + f) + print ('--------------------------------') +print List_Files \ No newline at end of file