Add: script to replace backslashes

This commit is contained in:
Aroy-Art 2023-12-20 21:21:07 +01:00
parent f00767fadf
commit 37aeb66d99
Signed by: Aroy
GPG key ID: DB9689E9391DD156

View file

@ -0,0 +1,22 @@
import os
import sys
def replace_backslash(directory):
for root, _, files in os.walk(directory):
for filename in files:
if "\\" in filename:
file_path = os.path.join(root, filename)
new_filename = filename.replace("\\", "")
new_file_path = os.path.join(root, new_filename)
os.rename(file_path, new_file_path)
print(f"Renamed {file_path} to {new_file_path}")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script_name.py <directory_path>")
else:
directory_path = sys.argv[1]
if not os.path.exists(directory_path):
print("Directory not found.")
else:
replace_backslash(directory_path)