Reputation: 13
I have a little question, I have a directorie which contain directories (with files in it) and files. Can i use os.walk to treat files 1 by 1 but not the files into directories ?
Thank you for your answers
Upvotes: 1
Views: 880
Reputation: 13
My code with os.listdir: enter image description here
I think there is something easier for both but i don't know what :/
Upvotes: 0
Reputation: 13
Well for exemple i have a directorie like that:
boite_noire/ .....helloworld/ .....test1.txt .....test2.txt
I would like somethink like that at the end of the script: boite_noire/ .....helloworld/ .....test1/ .....test2/
And in the test1 dirctorie I put test1.txt and same for test2.
I tried listdir but without success and yes os.walk.next()2 should be a good idea cause my problem is when i run my script my os.walk scan the directories and files inside and i don't want to, i only want him to scan the files at the source.
My code with os.walk enter image description here
Upvotes: 0
Reputation: 2685
Do you want to only list the files in the highest level dir without going in to sub-dirs? os.listdir should do it for you.
You can easily add a check to skip dirs this way
for f in os.listdir(path):
if f.is_dir():
continue
print f
Upvotes: 1