-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenameFiles.py
More file actions
30 lines (26 loc) · 1.16 KB
/
renameFiles.py
File metadata and controls
30 lines (26 loc) · 1.16 KB
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
# This code was generated by ChatGPT, a large language model trained by OpenAI,
# based on the GPT-3.5 architecture. ChatGPT is a general-purpose language model
# that can perform a wide variety of tasks, including generating code. Please
# note that while ChatGPT tries to generate correct and functional code, it may
# not always produce optimal or secure code. Therefore, it is important to
# review and test the code generated by ChatGPT carefully before using it in any
# production environment.
#
# This script renames all files in a directory and its subdirectories by
# replacing the character ':' with '-', while not modifying the names of the
# directories and subdirectories.
import os
import sys
def rename_files(path):
for root, dirs, files in os.walk(path):
for file in files:
old_name = os.path.join(root, file)
new_name = os.path.join(root, file.replace(':', '-'))
if old_name != new_name:
os.rename(old_name, new_name)
if __name__ == '__main__':
if len(sys.argv) != 2:
print('Usage: python rename_files.py <directory_path>')
sys.exit(1)
path = sys.argv[1]
rename_files(path)