1- # Script Name : batch_file_rename.py
2- # Author : Craig Richards
3- # Created : 6th August 2012
4- # Last Modified :
5- # Version : 1.0
6-
7- # Modifications :
8-
9- # Description : This will batch rename a group of files in a given directory, once you pass the current and new extensions
10-
11- import os # Load the library module
12- import sys # Load the library module
13-
14- work_dir = sys .argv [1 ] # Set the variable work_dir with the first argument passed
15- old_ext = sys .argv [2 ] # Set the variable work_dir with the first argument passed
16- new_ext = sys .argv [3 ] # Set the variable work_dir with the first argument passed
17-
18- files = os .listdir (work_dir ) # Set the variable files, by listing everything in the directory
19- for filename in files : # Loop through the files
20- file_ext = os .path .splitext (filename )[1 ] # Get the file extension
21- if old_ext == file_ext : # Start of the logic to check the file extensions, if old_ext = file_ext
22- newfile = filename .replace (old_ext , new_ext ) # Set newfile to be the filename, replaced with the new extension
23- os .rename ( # Write the files
24- os .path .join (work_dir , filename ),
1+ # Script Name : batch_file_rename.py
2+ # Author : Craig Richards
3+ # Created : 6th August 2012
4+ # Last Modified :
5+ # Version : 1.0
6+
7+ # Modifications :
8+
9+ # Description : This will batch rename a group of files in a given directory, once you pass the current and new extensions
10+
11+ import os # Load the library module
12+ import sys # Load the library module
13+
14+ work_dir = sys .argv [1 ] # Set the variable work_dir with the first argument passed
15+ old_ext = sys .argv [2 ] # Set the variable work_dir with the first argument passed
16+ new_ext = sys .argv [3 ] # Set the variable work_dir with the first argument passed
17+
18+ files = os .listdir (work_dir ) # Set the variable files, by listing everything in the directory
19+ for filename in files : # Loop through the files
20+ file_ext = os .path .splitext (filename )[1 ] # Get the file extension
21+ if old_ext == file_ext : # Start of the logic to check the file extensions, if old_ext = file_ext
22+ newfile = filename .replace (old_ext , new_ext ) # Set newfile to be the filename, replaced with the new extension
23+ os .rename ( # Write the files
24+ os .path .join (work_dir , filename ),
2525 os .path .join (work_dir , newfile ))
0 commit comments