python - How can I move selected files into a folder? -


This replaces each file in the program folder with a specific date in new folders. Most filenames follow this method:

  20120509_1324654_house.jpg 20120509_1324654_roof.jpg   

But there may be some names like:

  20120509_dog.txt 20120509_dog.txt 20120509_dog.xtpg2020509_dog.txt   

This is the files that I would like to place in a folder "animals", but I do not know my code How to edit, so that the programmers can create the folder and put those files there.

This is by far I have:

  Import Import from zip file Import import import import time import Import import Import import imported from default fix copyfile pat = R '(\ D +) (?: _ \ D +)? _ (\ W +?) [\ ._]. * To import file from 'archive default note' src = 'D: / test / src /' or glob.glob to name ('D: Os.listdir (src): print name dict_date = defaultdict (lambda: default) Dict (list): if os.path.isfile (os.path.join (src, fil)): date, subfolder = red match (pat, file) group () dict_date [date] [subfolder] .dictdate For the date in apend (fil): dict_date [date], for subfolder: Try: except os.makedirs (OS path.join (src, date, subfolder). Os.error: accordingly [date] [subfolder ]: Filfile (os.path.join (src, fil), os.path.join (src, date, subfolder, file) days Date with: zipfile (OS path.join (src, '{0} .zip.format (date)),' w) as myzip: dict_date for subfolder [Date] Oslistdir (os.path For fil in .join (src, date, subfolder): if not with fil.ends ('.zip'): myzip.write (os.path.join (src, date, subfolder, fil)) directory = Src os.chdir (directory) file = glob.glob ('* .txt') for file: os.unlink (filename) files2 = glob.glob ('* .png') in files2: os.unlink ( The filename is printed in Glob.glob ('D: / test / src / *') for the name of the print ("\ n files are now in the folder \ n"): Print name    

"itemprop =" text ">

/ Code>

Comments