Good day! Tell me how can I list the files in the folder with a specific extension?
Found on the Internet a piece of code:
import os directory = './' files = os.listdir(directory) fzip = filter(lambda x: x.endswith('.zip'), files) The script is executed print(fzip) but I get instead of (f1.zip, f2.zip ...) <filter object at 0x0318C990>
What could be the problem? Thanks in advance for your help.
from glob import glob; glob.glob('/path/to/*.zip')from glob import glob; glob.glob('/path/to/*.zip')? - MaxUlistdir + endswithmay be (for example,pathlib.Path(directory).glob('*.zip')), then you can also ask your original question "Search for files by extension in Python" ask (if the search does not find such a question). - jfs