-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_rename.py
More file actions
38 lines (32 loc) · 811 Bytes
/
Copy pathfile_rename.py
File metadata and controls
38 lines (32 loc) · 811 Bytes
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
"""
Rename files from a folder
Get: http://icarus.cs.weber.edu/~hvalle/hafb/prank.zip
"""
import os
def rename_files():
"""
Rename files in a folder
:return: nothing
"""
folder_dir = r"C:\Users\CCETeach03.AD\Desktop\hafb\prankOrig"
files = os.listdir(folder_dir)
saved_path = os.getcwd() # save current directory
# Go the the files' directory
os.chdir(folder_dir)
for file in files:
# Remove digits from name
new_file = file.lstrip('0123456789')
print("old name", file, "new name", new_file)
# Rename file to new name
os.rename(file, new_file)
# Get back home
os.chdir(saved_path)
def main():
"""
test function
:return: nothing
"""
rename_files()
if __name__ == '__main__':
main()
exit(0)