python
List all files of a directory using os Python
from os import listdir
from os.path import isfile, join
dirPath = "path/to/my/directory"
allFileAndFolders = listdir(dirPath)
allFiles = [f for f in allFileAndFolders if isfile(join(dirPath, f))]
You can use the os.listdir() method to list all files and folders inside a directory. You need to pass the directory path to this method and it will return you everything inside the directory.
Was this helpful?
Similar Posts
- Show all files in a dictionary as a list in Python
- Check if a directory exists using Python
- How to install packages using pip according to the requirements.txt file from a local directory?
- Python - regex , remove all single characters,replace all single chars,char
- Convert all string values in a list to integers using python
- Find all indexes of an item in a list using python
- Get all values by key name from a list of dictionaries Python