arcpy - How to extract, rename, and move files via scripting -


i beginner in python, problem daunting. using arcgis 10.2 python 2.7

i have 3,000 zip files (winzip) each contain 4 shapefiles describing different vector features. these shapefiles have same 4 identical names inside each zip file. time series, same 4 data sets broken individual dates.

the name of zip file contains string somewhere in middle of name need retrieve , include in name of extracted shapefiles.

then need move each renamed shapefile different directory based on type.

for example:

 usdm_20001001.zip (i need 20001001 title)     |--di_callout.shp (needs renamed c20001001 , moved directory = callout)     |--di_type.shp (needs renamed t20001001 , moved directory = type)     |--file 3     |--file 4 

and on, 3,000 times.

python has zip interface. i've put little script has pieces need need look-up or conversion names , paths; there's not enough info in question decide on names , can't follow folder structure.

import sys, os, zipfile  infolder = sys.argv[1]  zfile in os.listdir(infolder + "\*.zip"):     # open archive     archive = zipfile.zipfile(infolder + "\\" + zfile)     # base name (no extension) , split     # exract id.     zname, zext = os.splitext(zfile)     zsplit = zname.split("_")     basename = "c%s" % zsplit[1]      zdir = infolder + "\\" + basename      # if folder doesn't exist create     if not os.path.exists(zdir):         os.mkdir(zdir)      # setp through each file in archive     # extracting each 1 go.     member in archive.infolist():         inname, inext = os.splitext(member.filename)         # not sure naming here, need         # string manipulation         outfilename = "notsure" + inext          # not sure extract diffent name         # extract , rename         archive.extract(member,zdir)         os.rename(zdir + "\\" + member.filename, zdir + "\\" + outfilename) 

all pieces there: splitting strings, working zip file, testing & creating folders, renaming files , splitting file names extensions. use basis , should on way.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -