Advertisement
Xenithz

picRename

May 19th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. import os,re,time
  2. folder1 = '/root/python/picA'
  3. folder2 = '/root/python/picB'
  4. Dicta = {}
  5. Dictb = {}
  6. for path, subdirs, files in os.walk(folder1):
  7.     for name in files:
  8.         Dicta[time.ctime(os.path.getmtime(os.path.join(path, name)))] = os.path.join(path, name)
  9. for path, subdirs, files in os.walk(folder2):
  10.     for name in files:
  11.         Dictb[time.ctime(os.path.getmtime(os.path.join(path, name)))] = os.path.join(path, name)
  12. for name in Dicta:
  13.    if name in Dictb:
  14.        #print Dicta[name]+' => '+os.path.dirname(Dicta[name])+'/'+os.path.split(Dictb[name])[1]
  15.        os.rename(Dicta[name],os.path.dirname(Dicta[name])+'/'+os.path.split(Dictb[name])[1])
  16. print "Complete"
  17.  
  18.  
  19. # Ref.
  20. #http://www.tutorialspoint.com/python/python_dictionary.htm
  21. #http://docs.python.org/release/2.5.2/lib/typesmapping.html
  22. #http://stackoverflow.com/questions/2909975/python-list-directory-subdirectory-and-files
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement