[Tutor] select particular directories and files

questions anon questions.anon at gmail.com
Tue Aug 30 01:52:42 CEST 2011


I am trying to select particular files within a particular subdirectory, I
have been able to do both but not together!
When I try to select my files within the dir loop nothing comes up, but when
I leave the files outside the dir loops it selects all the files
not just the ones in the dirs I have selected.
The code I am using is:

import os

MainFolder=r"D:/samples/"

for (path, dirs, files) in os.walk(MainFolder):
    for dir in dirs:
        if dir=='01':
            print "selected directories are:",dir

            for ncfile in dir:
                  if ncfile[-3:]=='.nc':
                        print "ncfiles are:", ncfile

Any feedback will be greatly appreciated!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110830/dc68b723/attachment.html>


More information about the Tutor mailing list