| import os |
| import random |
|
|
| |
| dir1 = 'cloth_s' |
| dir2 = 'cloth-mask_s' |
|
|
| |
| assert sorted(os.listdir(dir1)) == sorted(os.listdir(dir2)), "Directories do not have the same set of files" |
|
|
| |
| filenames = [os.path.splitext(f)[0] for f in os.listdir(dir1)] |
| |
| random.shuffle(filenames) |
|
|
| |
| new_filenames = {os.path.splitext(f)[0]: new_name for f, new_name in zip(sorted(os.listdir(dir1)), filenames)} |
|
|
| |
| for dir in [dir1, dir2]: |
| for old_file in os.listdir(dir): |
| old_base, ext = os.path.splitext(old_file) |
| |
| if old_base in new_filenames: |
| new_file = new_filenames[old_base] + ext |
| os.rename(os.path.join(dir, old_file), os.path.join(dir, new_file)) |
|
|
|
|