routine changes

This commit is contained in:
Joel Mathew Thomas
2024-05-11 15:10:56 +05:30
parent b1c60c2c30
commit eb31d5777e
9 changed files with 75 additions and 10 deletions
+28
View File
@@ -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)