| 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) | |