👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
I"m trying to make a script to list all directory, subdirectory, and files in a given directory.
I tried this:
import sys,os
root = "/home/patate/directory/"
path = os.path.join(root, "targetdirectory")
for r,d,f in os.walk(path):
for file in f:
print os.path.join(root,file)
Unfortunatly it doesn"t work properly.
I get all the files, but not their complete paths.
For example if the dir struct would be:
/home/patate/directory/targetdirectory/123/456/789/file.txt
It would print:
/home/patate/directory/targetdirectory/file.txt
What I need is the first result. Any help would be greatly appreciated! Thanks.
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from Python list directory, subdirectory, and files, check other code Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano Python list directory, subdirectory, and files
- Deutsch Python list directory, subdirectory, and files
- Français Python list directory, subdirectory, and files
- Español Python list directory, subdirectory, and files
- Türk Python list directory, subdirectory, and files
- Русский Python list directory, subdirectory, and files
- Português Python list directory, subdirectory, and files
- Polski Python list directory, subdirectory, and files
- Nederlandse Python list directory, subdirectory, and files
- 中文 Python list directory, subdirectory, and files
- 한국어 Python list directory, subdirectory, and files
- 日本語 Python list directory, subdirectory, and files
- हिन्दी Python list directory, subdirectory, and files
San Francisco | 2023-03-29
I was preparing for my coding interview, thanks for clarifying this - Python list directory, subdirectory, and files in Python is not the simplest one. I am just not quite sure it is the best method
California | 2023-03-29
Maybe there are another answers? What Python list directory, subdirectory, and files exactly means?. Checked yesterday, it works!
California | 2023-03-29
code Python module is always a bit confusing 😭 Python list directory, subdirectory, and files is not the only problem I encountered. I am just not quite sure it is the best method