+ 3
List file in each folder
lets say i have folder named A. in A folder, containing B folder, C folder, and a file. in B folder contain Folder again and each folder contain file. its like a tree. so in python, how to get list all file adress with automatic. kinda difficult to explain. any suggestion? thnx before
6 Answers
+ 8
This is called 'walking' the tree / directories. I believe 'os' contains these functions (I'm checking).
edit:
http://pythoncentral.io/how-to-traverse-a-directory-tree-in-JUMP_LINK__&&__python__&&__JUMP_LINK-guide-to-os-walk/
import os
print(os.walk.__doc__)
+ 5
@Sammie Temmy
I regularly check facts, so I just went to CodePlayground to confirm help() was still non-functional. I got a Time Limit Exceeded, then...much to my surprise (it hasn't worked for a year) I got a *gigantic* help() dump...followed by another TLE.
I suspected SoloLearn updated for bigger output; this appears to confirm. Thanks for adding that.
@Kevin1010
I should not have assumed you were just on CodePlayground; Python's help() system is definitely useful. You can also try Python Docs by Little Drops in Google Play; they just added Dive Into Python and it works offline.
+ 3
Kirk Schafer, __doc__ is a very good hint
+ 2
os.walk will do it...
>> help(os) will also help
>>Use Qpython/Qpython3 2.7 and 3.x respectively
+ 2
@Kirk Schafer... I use both 2.x and 3.x
Just kinda looks like 2.7's pretty slow..
All the best for y'all python codersđđ
0
i will learn it. big thanks to you. hahaha. i never expect there a function can do that