forked from Zeldazackman/Core-Station2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
83 lines (69 loc) · 3.38 KB
/
script.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
def read_and_modify_files_in_directory(directory_path):
try:
print(f"Scanning directory: {directory_path}")
file_count = 0
for root, dirs, files in os.walk(directory_path):
level = root.replace(directory_path, '').count(os.sep)
indent = ' ' * 4 * level
print(f"{indent}Entering directory: {root}")
for file in files:
if file.endswith(".dm"):
file_count += 1
file_path = os.path.join(root, file)
print(f"{indent} Found .dm file: {file_path}")
modify_dm_file(file_path, indent)
elif file.endswith(".dmm"):
file_count += 1
file_path = os.path.join(root, file)
print(f"{indent} Found .dmm file: {file_path}")
modify_dmm_file(file_path, indent)
if file_count == 0:
print(f"No .dm or .dmm files found in directory: {directory_path}")
else:
print(f"Total files modified: {file_count}")
except Exception as e:
print(f"An error occurred while reading files: {e}")
def modify_dm_file(file_path, indent):
try:
with open(file_path, 'r', encoding='utf-8') as file:
contents = file.read()
# Perform flexible replacements (catch "var/obj/item/weapon" and others)
modified_contents = contents.replace("obj/item/weapon", "obj/item")
modified_contents = modified_contents.replace("obj/item/device", "obj/item")
# Check if any changes were made
if contents != modified_contents:
with open(file_path, 'w', encoding='utf-8') as file:
file.write(modified_contents)
print(f"{indent} File modified successfully: {file_path}")
else:
print(f"{indent} No changes made to: {file_path}")
except FileNotFoundError:
print(f"{indent} Error: The file {file_path} was not found.")
except Exception as e:
print(f"{indent} An error occurred while modifying {file_path}: {e}")
def modify_dmm_file(file_path, indent):
try:
with open(file_path, 'r', encoding='utf-8') as file:
contents = file.read()
# Perform flexible replacements (catch "var/obj/item/weapon" and others)
modified_contents = contents.replace("obj/item/weapon", "obj/item")
modified_contents = modified_contents.replace("obj/item/device", "obj/item")
# Check if any changes were made
if contents != modified_contents:
with open(file_path, 'w', encoding='utf-8') as file:
file.write(modified_contents)
print(f"{indent} .dmm file modified successfully: {file_path}")
else:
print(f"{indent} No changes made to .dmm file: {file_path}")
except FileNotFoundError:
print(f"{indent} Error: The .dmm file {file_path} was not found.")
except Exception as e:
print(f"{indent} An error occurred while modifying .dmm file {file_path}: {e}")
# Get the directory where the script is located
directory_path = os.path.dirname(os.path.abspath(__file__))
print(f"Script directory: {directory_path}")
# Start the process
read_and_modify_files_in_directory(directory_path)
# Prevent the script from closing immediately
input("\nProcess completed. Press Enter to close the script...")