This page demonstrates Python tips and tricks that I use in my everyday programming as an atmospheric science graduate student.
-Brian Blaylock

Tuesday, July 29, 2014

Python Accessing all the files in a directory

This is a handy link that gets file names from a directory:
http://stackoverflow.com/questions/18262293/python-open-every-file-in-a-folder

For example: 
path = 'C://Users/person/Pictures' for filename in glob.glob(os.path.join(path,'*.jpg')):

     print filename

results in:

C:\Users\Brian\Pictures\East.jpg
C:\Users\Brian\Pictures\North.jpg
C:\Users\Brian\Pictures\Rocketeer.jpg
C:\Users\Brian\Pictures\South.jpg
C:\Users\Brian\Pictures\WIN_20140711_105811_edited.jpg

etc.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.