Nov-07-2023, 07:38 AM
Well, I'm no expert, but I often need to do the same thing to various XL files, so I make a list of the files, then choose 1 from the list. Then I either loop, or offer myself the choice of file again.
Something like this:
Maybe check if it is a zip file and ends in .xlsx Not sure how to check if it is a zip file!
But the experts here will know how to do that! Have fun!
Something like this:
import os import glob mypath = '/home/pedro/myPython/openpyxl/xlsx_files/' # can add files from various paths to xlfiles if needed xlfiles = glob.glob(mypath + '*.xlsx') for x in xlfiles: print('The XL files are', x) myfile = input('Copy and paste the whole path to the file you want from above ... ') while not os.path.isfile(myfile): print('Something wrong with this path or file. Choose another file.') myfile = input('Copy and paste the whole path to the file you want from above ... ')If myfile is not a valid file, os.path.isfile(myfile) returns False. However, this does not check if it is a valid XL file, just a valid file. Could be any type of file.
Maybe check if it is a zip file and ends in .xlsx Not sure how to check if it is a zip file!
But the experts here will know how to do that! Have fun!