mardi 4 septembre 2018

moving files to folders after they got read and seperated by a variable

I have created a python script that reads a variable (FILTER) from a lot files in a folder and puts the result on screen. However, there are 4 types of variables and I would like this script to separate them all to the corresponding folders. Like move all of the files to a folder named "V" if they have variable FILTER = V, if they have FILTER = B, then move all of the B ones to folder named "B" The script below works to see which files have which filter on screen.

myList = []
for fitsName in glob.glob('*.fits'):
    hdulist = pyfits.open(fitsName)
    b = hdulist[0].header['FILTER']
    c = b
    myList.append(c)
    hdulist.close()

for item in sorted(myList):
    print item

so it is like from the code above, if c= FILTERNAME1 move to SOMEFOLDER1 if c = FILTERNAME2 move to SOMEFOLDER2 and so on.. I could not write a working code line for this so any help would be appreciated a lot.

Aucun commentaire:

Enregistrer un commentaire