[Tutor] Walking a directory
Jacob S.
keridee at jayco.net
Tue Jan 18 03:58:27 CET 2005
Kent's suggestions are always my favorites, along with others,
c. --nevermind
To get the full path in your list-- change Kent's to this
import os
filelist = []
for root,directories,filenames in os.walk("Aircraft"):
for filename in filenames:
if filename.endswith("-set.xml"):
filelist.append(os.path.join(root,filename))
for x in filelist:
print x
> What I want to do is rather simple, but I cannot find any good
> documentation for something like this.
>
> The directory structure is sort of like this:
>>Aircraft
>>>A-10
> +A-10cl-set.xml
> +A-10fg-set.xml
>
> For example Aircraft/A-10/A-10cl-set.xml
>
> Now I want to loop though each aircrafts folder (such as A-10) and
> find each *-set.xml file, get the aircraft part (such as A-10cl) and
> add it to a list.
>
> While this does seem simple, how is the question.
>
> I know about the walk function, but cannot find any good examples for it.
> --
> <Arthur/>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
More information about the Tutor
mailing list