-
Notifications
You must be signed in to change notification settings - Fork 0
/
ext_rename.py
38 lines (32 loc) · 1.06 KB
/
ext_rename.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'''
Author: Nathaniel
----------------------------------------------------------------------------------------------
Script Usage: Renames all extensions specified by the user to the extension the user chooses
How to use: script run via command line. first arg is current ext, second arg is final ext.
Version: python 3.8.7
----------------------------------------------------------------------------------------------
'''
#!/usr/bin/env python3
import os
import sys
#checks for correct user input
def check_dot(ext):
temp = list(ext)
if temp[0] != '.':
print('Extensions must begin with a Dot --> .\n')
print('Nothing implimented.\nExiting...')
exit()
#assigns
ext_current = sys.argv[1]
ext_final = sys.argv[2]
#call function
check_dot(ext_current)
check_dot(ext_final)
#gets current directory
current_dir = os.getcwd()
for file in os.listdir(current_dir): #listdir
fileName, fileExt = os.path.splitext(file) #splitting file text
if fileExt == ext_current:
fileExt = ext_final
newExt = '{}{}'.format(fileName,fileExt) #resetting format
os.rename(file, newExt)