+ 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

23rd Sep 2017, 2:23 PM
Kevin AS
Kevin AS - avatar
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__)
23rd Sep 2017, 2:34 PM
Kirk Schafer
Kirk Schafer - avatar
+ 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.
24th Sep 2017, 2:30 PM
Kirk Schafer
Kirk Schafer - avatar
+ 3
Kirk Schafer, __doc__ is a very good hint
23rd Sep 2017, 8:30 PM
Sergej Schelle
Sergej Schelle - avatar
+ 2
os.walk will do it... >> help(os) will also help >>Use Qpython/Qpython3 2.7 and 3.x respectively
24th Sep 2017, 2:16 PM
stemitom
stemitom - avatar
+ 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😍😍
24th Sep 2017, 2:57 PM
stemitom
stemitom - avatar
0
i will learn it. big thanks to you. hahaha. i never expect there a function can do that
23rd Sep 2017, 2:41 PM
Kevin AS
Kevin AS - avatar