File size: 2,240 Bytes
0038e9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import shutil

# Automatically get the directory where the script is located
source_dir = os.path.dirname(os.path.abspath(__file__))
odcs_decrypted_dir = os.path.join(source_dir, "TMP")

# Define valid hex digits (uppercase)
hex_digits = "0123456789ABCDEF"

# Define valid prefixes and create their directories with subfolders for hex digits
prefixes = ["live", "live2"]

for prefix in prefixes:
    prefix_dir = os.path.join(odcs_decrypted_dir, prefix)
    os.makedirs(prefix_dir, exist_ok=True)
    # Create subfolders 0-9 and A-F within each prefix folder
    for digit in hex_digits:
        subfolder = os.path.join(prefix_dir, digit)
        os.makedirs(subfolder, exist_ok=True)

# Iterate over each .odc file in the ODCsDecrypted folder
for filename in os.listdir(odcs_decrypted_dir):
    if filename.endswith(".odc"):
        # Check if the file name contains a '$' and starts with one of the valid prefixes
        if "$" in filename:
            # Check for live2$ first, then live$
            if filename.startswith("live2$"):
                prefix = "live2"
            elif filename.startswith("live$"):
                prefix = "live"
            else:
                print(f"Skipping file {filename}: does not start with a valid prefix.")
                continue

            # Split the filename by '$' to extract the UUID part
            parts = filename.split("$", 1)
            if len(parts) != 2:
                print(f"Skipping file {filename}: unexpected filename format.")
                continue
            uuid_part = parts[1]
            # Get the first character of the UUID and convert to uppercase
            first_digit = uuid_part[0].upper()
            if first_digit in hex_digits:
                source_file = os.path.join(odcs_decrypted_dir, filename)
                dest_file = os.path.join(odcs_decrypted_dir, prefix, first_digit, filename)
                print(f"Moving {filename} to {prefix}/{first_digit}/")
                shutil.move(source_file, dest_file)
            else:
                print(f"Skipping file {filename}: first character '{uuid_part[0]}' is not a valid hex digit.")
        else:
            print(f"Skipping file {filename}: missing '$' in filename.")