Advertisement
dc5553

Recursively drill through files and pull specific ext

Jun 26th, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. #!/usr/bin/python
  2. # coding: utf-8
  3. import sys,os
  4.  
  5. filetype = sys.argv[1]
  6. startdir = sys.argv[2]
  7. todir = sys.argv[3]
  8.  
  9. if sys.argv[1] == '-h':
  10.     print ' proper syntax is filetype, starting directory, and to directory i.e. pullfiles.py jpg /tmp /home/user'
  11.     sys.exit()
  12. if len(sys.argv) < 4:
  13.     print ' proper syntax is filetype, starting directory, and to directory i.e. pullfiles.py jpg /tmp /home/user'
  14.     sys.exit()
  15.  
  16. for root, dir, files in os.walk(str(startdir)):
  17.         for file in files:
  18.             if ("."+filetype) in file:
  19.         os.system('cp ' + root + '/' + file + ' ' + str(todir))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement