All the files in a given directory can be listed using ‘os’ library in python.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# importing the os library import os # Creating an empty list to store all the paths AbsolutePaths=[] # Specifying the directory path DirectoryPath='/Users/farukh/Python ML IVY' # Walking inside all the directories recursively for DirPath,_,FileNames in os.walk(DirectoryPath): for files in FileNames: AbsolutePaths.append(os.path.abspath(os.path.join(DirPath, files)) ) # Printing the filenames AbsolutePaths |
Sample outputs for the above command run in Jupyter notebook
Author Details
Lead Data Scientist
Farukh is an innovator in solving industry problems using Artificial intelligence. His expertise is backed with 10 years of industry experience. Being a senior data scientist he is responsible for designing the AI/ML solution to provide maximum gains for the clients. As a thought leader, his focus is on solving the key business problems of the CPG Industry. He has worked across different domains like Telecom, Insurance, and Logistics. He has worked with global tech leaders including Infosys, IBM, and Persistent systems. His passion to teach inspired him to create this website!