How to selectively iterate over files with Python
I would like to iterate through files in a specified directory which are bigger then 100 kb and end with a *.zip. How can this be done in a efficient way? Will go through any zip files but not necessarily files which are bigger than 100kb; for i in os.listdir(os.getcwd()): if i.endswith(".zip"): ##print i continue else: continue How can I incoprporate it in the if conditions? ie (if i.endswith(".zip") and >100kb). How could I used this file as an argument with myOtherPythonScript.py?
You could try something like this... for i in os.listdir(os.getcwd()): if i.endswith(".zip"): if os.path.getsize(i) > 10240: print i continue else: continue
endswith and os.path.getsize are the two functions you want. import os file_names = [os.path.join(path, file_name) for file_name in os.listdir(path)] for file_name in file_names: if file_name.endswith('zip') and os.path.getsize(file_name) >= 100*1024: pass else: pass
QGIS XML plugin to read and parse second try
making autogenerated module members visible to PyDev/PyLint static analysis
Python Assistance with a small code
Unhandled exception aborting python process on Windows, but not on OS X
What does if random.randint(0,1) mean? [closed]
How to check if list1 contains some elements of list2?
Python logging from multiple modules to same log file
Python drag and drop, get filenames [closed]
Upload multiple files with Tornado Web Server and Nginx
How to read a simple binary file
How to run mysql in Django 1.5.5 with Python 3.3.4 in Windows 7
How can I do maps involving string fields in rethinkdb?
Scrollbar not functioning properly Tkinter
Is there a way to quickly create many files many sequential files (ex1 . . . ex 50) in Python?
Pygame playing sound with pygame.mixer.music.load(file) gives NoneType error
How to update multiple values in Mongodb using pymongo?