How To Skip A File If It's Not There In The Directory?
So here i'm reading a fits file. path = '/home/Desktop/2d_spectra' for filename in os.listdir(path): if filename.endswith('_e2ds_A.fits'): e2ds_hdu = fits.open(filename)
Solution 1:
To test that 4 files exist in a directory, you can do this:
filenames = {'filename1.ext', 'filename2.ext', 'filename3.ext', 'filename4.ext'}
all_exist = filenames.issubset(os.listdir(path))
Solution 2:
Solution 3:
Use os.path.exists(path/to/file)
before opening it.
Post a Comment for "How To Skip A File If It's Not There In The Directory?"