list all files in directory code example

Example 1: python list all files in directory

from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

Example 2: display all files in a directory linux

ls command list computer files in a directory in Unix OS with next structure:
ls [OPTION]... [FILE]...
Examples:
ls -l #display all files in current directory with  (-l) long format.
ls -a /directory #display all hidden files in given directory that start with .

Example 3: os list all files in one dir

import glob
print(glob.glob("/home/adam/*.txt"))

Example 4: list all files in a directory and subdirectory linux

find . -type f -follow -print