Hướng dẫn python list all subfolders
This below class would be able to get list of files, folder and all sub folder inside a given directory Show
Whereas Sample Directory looks like
Result Obtained This post will discuss how to list all subdirectories in a directory in Python. 1. Using os.listdir() functionA simple solution to list all subdirectories in a directory is using the
Download Code
Download Code 2. Using os.scandir() functionWith Python 3.5, you can use the
Download Code
Download Code 3. Using pathlib moduleYou can also use the
Download Code
Download Code 4. Using os.walk() functionTo search in subdirectories, consider using the
Download Code 5. Using glob moduleFinally, you can use the
Download Code
Download Code That’s all about listing all subdirectories in a directory in Python. Thanks for reading. Please use our online compiler to post code in comments using C, C++, Java, Python, JavaScript, C#, PHP, and many more popular programming languages. Like us? Refer us to your friends and help us grow. Happy coding 🙂 |