-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRGS_SAVE_PULL
More file actions
83 lines (68 loc) · 3.4 KB
/
RGS_SAVE_PULL
File metadata and controls
83 lines (68 loc) · 3.4 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
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
import shutil
import getpass
# Defines the current logged in windows user
user_name = getpass.getuser()
# Defines the Unique_ID by capturing the folder name located at the root_folder while excluding the t folder
root_folder = rf"C:\Users\{user_name}\AppData\Local\Packages\PerfectWorldEntertainment.GFREMP2_jrajkyc4tsa6w\SystemAppData\wgs"
exclude_folder = "t"
unique_id = [
d for d in os.listdir(root_folder)
if os.path.isdir(os.path.join(root_folder, d)) and d != exclude_folder
]
# Destination folder path, this can be whatever folder you want
destination_folder = rf"C:\Users\{user_name}\Documents\RSG_Temp"
profile_file = "profile.sav"
# Source folder path
source_folder = rf"C:\Users\{user_name}\AppData\Local\Packages\PerfectWorldEntertainment.GFREMP2_jrajkyc4tsa6w\SystemAppData\wgs\{unique_id[0]}"
# Defines the Specific_mappings varible by listing subdirectories of the source_folder
specific_mappings = [d for d in os.listdir(source_folder) if os.path.isdir(os.path.join(source_folder, d))]
# Prefix to be excluded
excluded_prefix = "container"
# Create the destination folder if it doesn't exist
if not os.path.exists(destination_folder):
os.makedirs(destination_folder)
print(f"Created destination folder: {destination_folder}")
# Empty the entire destination folder
for file_name in os.listdir(destination_folder):
file_path = os.path.join(destination_folder, file_name)
if os.path.isfile(file_path):
os.remove(file_path)
print(f"Removed existing file: {file_name}")
# Iterate through the source folder and its subdirectories
for root, dirs, files in os.walk(source_folder):
for file_name in files:
if not file_name.startswith(excluded_prefix):
source_file_path = os.path.join(root, file_name)
destination_file_path = os.path.join(destination_folder, file_name)
try:
shutil.copy2(source_file_path, destination_file_path)
print(f"File '{file_name}' copied successfully.")
except FileNotFoundError:
print(f"File '{file_name}' not found in the source folder.")
except Exception as e:
print(f"Error copying '{file_name}': {e}")
# Get a list of files in the destination folder
destination_files = [f for f in os.listdir(destination_folder) if os.path.isfile(os.path.join(destination_folder, f))]
# Sort files by size in ascending order
sorted_files = sorted(destination_files, key=lambda f: os.path.getsize(os.path.join(destination_folder, f)))
# Rename files according to the mapping
save_file_counter = 0
for file_name in sorted_files:
mapped_suffix = ""
new_file_name = ""
if file_name in specific_mappings:
index = specific_mappings.index(file_name)
new_file_name = f"save_{index}.sav"
mapped_suffix = " [mapped]"
else:
new_file_name = f"save_{save_file_counter}.sav"
save_file_counter += 1
if file_name == sorted_files[0]:
# Rename the smallest file to profile.sav
os.rename(os.path.join(destination_folder, file_name), os.path.join(destination_folder, profile_file))
print(f"Renamed smallest file ({file_name}) to '{profile_file}'")
else:
# Rename other files to save_*.sav
os.rename(os.path.join(destination_folder, file_name), os.path.join(destination_folder, new_file_name))
print(f"Renamed file ({file_name}) to '{new_file_name}'{mapped_suffix}")