python


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

Related Links

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?

Categories

HOME
ssas-2012
pug
jenkins-plugins
nlp
sed
scipy
fparsec
couchdb-2.0
docker-windows
websphere-liberty
nodemailer
internet-explorer-11
xcode8.3
actionscript-2
click
jboss7.x
tee
public-key-encryption
cs-cart
ida
dendrogram
raphael
google-ima
opencart2.3
owl-api
cgal
pcre
aurelia-binding
hibernate-cache
pljson
rhino
shibboleth
color-scheme
jboss-esb
nlb
concrete5-5.7
ddms
jupyter-console
knockout-3.0
median
finite-element-analysis
ivona
php-ews
tableau-server
w3-total-cache
proof
livefyre
seamless-immutable
bnd
chrome-remote-desktop
jexl
etherpad
fontconfig
iphone-developer-program
createobject
iostat
nssplitview
remoteapp
gradle-release-plugin
dac
financial
eml
handlebars.java
loose-typing
self-hosting
document-oriented-db
qbfc
sevenzipsharp
twython
searchkick
line-numbers
suffix-array
java-collections-api
unison
internal
roxygen
pyjade
convex-polygon
ruboto
haskell-platform
argb
mvccontrib
wcf-web-api
shim
die
objective-c-protocol
ajax.beginform
easygui
qtembedded
testunit
phpcrawl
junit3
yajl
graph-layout
internals
database-diagramming
data-execution-prevention

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App