1import os
2
3files = os.listdir('.')
4print(files)
5for file in files:
6 # do something
7
1lstJson = [f for f in os.listdir(str(self.pathJson)) if f.endswith('.json')]
2 return lstJson
1from os import listdir
2from os.path import isfile, join
3
4# Getting file path from user and store it on path variable
5path = input("Please enter a directory name:\n")
6
7# Try catch for printing error message if the user enter invalid path
8try:
9 # Getting list of file from the given path and store it in (onlyfiles) variable
10 onlyfiles = [f for f in listdir(path) if isfile(join(path, f))]
11
12 # Looping through the file and print each file
13 for file in onlyfiles:
14 print(file)
15
16except Exception as e:
17 # If there is some error, print error message
18 print("Incorrect path.")