Posted By

jlmarks on 03/01/14


file python consolidation

Versions (?)

Recursively consolodate all Files into one folder

 / Published in: Python

This file starts at the bottom of the tree and recursively moves all of the files from that tree into another folder. To avoid overwriting files I prepended all of the files with a 9digit number.

  1. import os, shutil
  4. def movefiles():
  5. x=0
  6. inputDir=raw_input("please enter the folder where the files are: ")
  7. outputDir=raw_input("please enter the destination folder")
  8. for root, dirs, files in os.walk(inputDir topdown=False):
  9. for name in files:
  10. newname="%09d"%x+name
  11. x+=1
  12. shutil.move(os.path.join(root, name), os.path.join(outputDir,newname))
  13. for name in dirs:
  14. os.rmdir(os.path.join(root, name))

Report this snippet  

You need to login to post a comment.