Last active
February 27, 2022 14:08
-
-
Save johnpili/57e1a33a69d36ea6e712ebc954a77b5e to your computer and use it in GitHub Desktop.
Rename files by removing the starting and matching string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from os import path | |
parameters = sys.argv[1:] | |
if len(parameters) == 0: | |
print(f"usage: {sys.argv[0]} <startswith-string>") | |
sys.exit(0) | |
if len(parameters) > 0: | |
for file in os.listdir(): | |
if file.startswith(parameters[0]) and path.isfile(file): | |
old_name = file | |
new_name = file[len(parameters[0]):] | |
print(f"Renaming {old_name} -> {new_name}") | |
os.renames(old_name, new_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment