lorenzocipriani

rename-file-uppercase.py

Apr 15th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. import sys
  2. from os import rename, path, listdir
  3.  
  4. ext = ".c01"
  5. cwd = "."
  6.  
  7. # Check if there is an argument on the command line and use it as the target folder
  8. if len(sys.argv) > 1:
  9.     cwd = sys.argv[1]
  10.    
  11. # Retrieve the file list from the defined/default working directory
  12. files = listdir(cwd)
  13. for fname in files:
  14.     # Check if the file has the required extension (ext)
  15.     if fname.lower().endswith(ext):
  16.         print("Rename file " + fname + " to " + fname.upper())
  17.         rename(path.join(cwd, fname), path.join(cwd, fname.upper()))
Add Comment
Please, Sign In to add comment