Help with Parsing

This is the place for queries that don't fit in any of the other categories.

Help with Parsing

Postby bbesase » Wed May 08, 2013 4:59 pm

I have to parse a folder for all types of files containing the word "Test" in it. Now I know how to parse for files ending in .txt and what not with this.

Code: Select all
for r,d,f in os.walk(path):
        for files in f:
            if files.endswith(".txt"):
                 print os.path.join(r,files)


But how would I split the words up into different tokens to check if it contains test or not. They will be in the form of blah.blah.test.blah

Thanks in advance
bbesase
 
Posts: 18
Joined: Wed May 08, 2013 1:57 pm

Re: Help with Parsing

Postby setrofim » Wed May 08, 2013 5:01 pm

You don't need to split the file name into tokens, you can just say
Code: Select all
if '.test.' in files:
    # ....
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: Help with Parsing

Postby bbesase » Wed May 08, 2013 5:37 pm

OK, thank you very much, that was way easier than I expected haha.
bbesase
 
Posts: 18
Joined: Wed May 08, 2013 1:57 pm


Return to General Coding Help

Who is online

Users browsing this forum: W3C [Linkcheck] and 1 guest