lorenzocipriani icon

rename-file-uppercase.py

lorenzocipriani | PRO | 04/15/19 11:58:42 PM UTC | 0 ⭐ | 260 👁️ | Never ⏰ | []
Python |

540 B

|

None

|

0 👍

/

0 👎

import sys
from os import rename, path, listdir
 
ext = ".c01"
cwd = "."
 
# Check if there is an argument on the command line and use it as the target folder
if len(sys.argv) > 1:
    cwd = sys.argv[1]
    
# Retrieve the file list from the defined/default working directory
files = listdir(cwd)
for fname in files:
    # Check if the file has the required extension (ext)
    if fname.lower().endswith(ext):
        print("Rename file " + fname + " to " + fname.upper())
        rename(path.join(cwd, fname), path.join(cwd, fname.upper()))

Comments