File size: 1,073 Bytes
df768f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os

def append_mask_to_labels(directory):
    # Loop through all files in the directory
    for filename in os.listdir(directory):
        # Get the full path of the current file
        file_path = os.path.join(directory, filename)

        # Ensure it's a file (not a subdirectory)
        if os.path.isfile(file_path):
            # Split the filename and its extension
            file_name, file_extension = os.path.splitext(filename)

            # Create the new filename by appending "_mask"
            new_filename = f"{file_name}_mask{file_extension}"

            # Get the full path for the new filename
            new_file_path = os.path.join(directory, new_filename)

            # Rename the file
            os.rename(file_path, new_file_path)
            print(f"Renamed: {filename} -> {new_filename}")

if __name__ == "__main__":
    # Replace with the path to your labels directory
    labels_directory = "/home/abdelrahman.elsayed/ROSE/masks"

    # Call the function to append "_mask" to each label
    append_mask_to_labels(labels_directory)