Reputation: 3
I have hundreds of image files in a folder named in the style "imagefile_xxxx.fit" where xxxx is a number, and corresponding data files, one for every image, in the style "datafile_xxxx.cat".
I've written a python programme that loops through all my data files and moves bad data to a directory of undesirables based on how many lines of data, and I want to then move the corresponding image file out of its directory to a folder of bad images, based on the number in the filenames.
So if datafile_0012.cat has been moved to the directory bad_data, move imagefile_0012.fit to the directory bad_images.
I am considering doing it the other way (copy good data to a directory and leave good and bad files mixed together in the original directory), but I still have the problem of copying image files based on the number in the data file name.
Upvotes: 0
Views: 145
Reputation: 510
A hint :
bdfn = "datafile_0012.cat"
bifn = bdfn.replace("datafile", "imagefile")
print(bifn)
Results in :
imagefile_0012.cat
Upvotes: 3