python get list of files in current directory code example
Example 1: python list files in current directory
import os
files = os.listdir('.')
print(files)
for file in files:
# do something
Example 2: store all files name in a folder python
import os
#this command will store all .txt files in same directories
ALL_FILES_IN_DIR = [ELEM for ELEM in os.listdir() if "txt" in ELEM]
#ALL DIRETORIES
ALL_DIR = [ELEM for ELEM in os.listdir() if "." not in ELEM]