shrug-l: Recursive Searching

Michael Berzinis idaeus at yahoo.com
Tue Nov 17 09:44:23 EST 2009


Sandell, 


We did something like this with some client legacy data recently--was 300+ folders, 1500 shapefiles. Depends if the destination field
classes have the same schema… could be done pretty quickly;
 
Searching all folders can be
done a bit easier when you know what you’re looking for, in this case File geodatabases.
Though in this case you can’t
just start at the highest level since the destination rests in the same folder
structure… but something like this would work
  - just some quick
sample code below, it’s not completed just showing an easy way to search the
folders...........

 
-// (forward slashes are
comments)
 
C#
 
//base path to folders
string basePath = @”C:\myData\Land_Mgmt\”;
 
//destination path
string destinationPath = @”C:\myData\Land_Mgmt\Statewide\LeaseManagement.gdb”;
 
//4 regions
string[] foldersToSearch = {“Region_I”,
“Region_II”, “Region_III”, “Region_IV”};
 
foreach (string folder in
foldersToSearch)
{
               //get all gdb
files from folder(s) – searchoption will search all sub-folders
               string
fileNames[] = Directory.GetFiles(basePath + folder, “*.gdb”,
SearchOption.AllDirectories);
 
               foreach(string
file in filenames)
               {
                              //create
a file object (easy reference to file)
                              FileInfo
pFileInfo = new FileInfo(file);
               
                              //open
the gdb
                              
                              //have
a statement recursively opening the 6 featureclasses
 
                              //search
all features
 
                              //append
to destinationPath
 
               }
}
 
Thomas M. Bass
Software Developer I 
3059 Highland Oaks Terrace 
Tallahassee, FL 32301  (map) 
o 850.385.3667 x3975 
c 850.559.9848 
Read about our
Forestry GIS Tools & Applications
mailto:tbass at landmarksystems.com
www.landmarksystems.com 
NOTICE: This communication is intended
only for the person or entity to whom it is addressed and may contain
confidential, proprietary, and/or privileged material. Unless you are the
intended addressee, any review, reliance, dissemination, distribution, copying
or use whatsoever of this communication is strictly prohibited. If you received
this in error, please reply immediately and delete the material from all
computers.
 




________________________________
From: "Sandell, Keith M." <sandell.keith at mail.dc.state.fl.us>
To: shrug-l at lists.dep.state.fl.us
Sent: Mon, November 16, 2009 3:57:52 PM
Subject: shrug-l: Recursive Searching

 
Hey Shruggers,
 
I need a way to search
through an undetermined number of folders and file geodatabases within these
folders for specific feature classes ("by name", 6 unique names) and
then append all the features from like feature classes into 6 feature classes
with the same unique names inside another file geodatabase. 
 
I need to go from having 100
File GDBs, with a total of 600 feature classes and about 12,000 features -- to
having 1 FGDB with 6 feature classes with about 12,000 features…a user’s
sick joke. I told them when they started this project to use one gdb and
filter, but they insisted on having separate gdbs and now they want the ability
to periodically consolidate them.
 
I have a basic understanding
of the List methods for workspaces and feature classes, but I have yet to
figure out how to integrate the sys module’s capacity to recursively
search through folders and create the lists at the same time so that I can
append all 12,000 features to the 6 feature classes.
 
The attached bmp shows the
basic folder hierarchy that I am dealing with and where I want the data to flow
from and to.
 
Any thoughts would be greatly
appreciated.
 
Thanks
 
Keith
Sandell, MBA
Management
Analyst
Bureau
of Probation and Parole Field Services
Office
of Community Corrections
Florida
Department of Corrections
2601
Blair Stone Road
Tallahassee,
Florida 32399
Phone:
(850) 410-3045
Fax:
(850) 487-4427
 
 
This
electronic message may contain protected health record/care information
intended for addressee(s) only. Unauthorized release or disclosure may violate
state and/or federal laws.


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.dep.state.fl.us/pipermail/shrug-l/attachments/20091117/1091ac25/attachment.htm


More information about the SHRUG-L mailing list