routine changes
This commit is contained in:
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
|
||||
def rename_folders_and_files(directory):
|
||||
# First, rename files and directories in subdirectories
|
||||
for root, dirs, files in os.walk(directory):
|
||||
for d in dirs:
|
||||
rename_folders_and_files(os.path.join(root, d))
|
||||
|
||||
# Then, rename files in the current directory
|
||||
for root, dirs, files in os.walk(directory):
|
||||
for f in files:
|
||||
old_path = os.path.join(root, f)
|
||||
new_path = os.path.join(root, f.lower().replace(" ", "_"))
|
||||
os.rename(old_path, new_path)
|
||||
|
||||
# Finally, rename directories in the current directory
|
||||
for root, dirs, _ in os.walk(directory):
|
||||
for d in dirs:
|
||||
old_path = os.path.join(root, d)
|
||||
new_path = os.path.join(root, d.lower().replace(" ", "_"))
|
||||
os.rename(old_path, new_path)
|
||||
|
||||
if __name__ == "__main__":
|
||||
root_directory = input("Enter the root directory path: ")
|
||||
rename_folders_and_files(root_directory)
|
||||
|
||||
Reference in New Issue
Block a user