Home arrow GIS Data & Resources arrow Scripts and Code arrow Python arrow Python: Walk Through Folders To Find File Geodatabases
Python: Walk Through Folders To Find File Geodatabases PDF Print E-mail

Written by Bert Granberg,

This code allows you to enter a directory/folder path and then recursively walks through all of the subdirectories and creates a text file with the full paths to all file geodatabases under the specified path. Makes use ofthe fact that all FGDB's seem to have a file called 'gdb' (no extension) within them.

Pretty useful for those of us that maintain a complex file structure (like the SGID's ftp site) or are just organizationally challenged.

 

import sys
import os
import string

searchFile = 'gdb'
cacheFolder = None

try:
    home = sys.argv[1]
except IndexError,e:
    print "Please enter your home directory: (no trailing slash) "
    home = raw_input()

homestr = string.replace(home,chr(47),chr(92))
homestr = string.replace(homestr,':','')
homestr = string.split(homestr, chr(92)) [-1]
homestr = string.replace(homestr,'.','')
                 
file = open('c:/FileGDBs_Under__' + homestr+ '.txt', 'w')
            
for root, dirs, files in os.walk(home):
    for x in files:
        if x == searchFile:
            cacheFolder = root
            print cacheFolder
            file.write(cacheFolder + chr(10))

file.close()

Users' Comments  
 

No comment posted

Add your comment

24, Jun. 2009
 
< Prev   Next >

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2010 AGRC

Optimized for