Skip to content

Instantly share code, notes, and snippets.



Created Dec 31, 2019
What would you like to do?
Python script for getting a list of files in a directory
import os
def getListOfFiles(dirName):
# create a list of file and sub directories
# names in the given directory
listOfFile = os.listdir(dirName)
allFiles = list()
# Iterate over all the entries
for entry in listOfFile:
# Create full path
fullPath = os.path.join(dirName, entry)
# If entry is a directory then get the list of files in this directory
if os.path.isdir(fullPath):
allFiles = allFiles + getListOfFiles(fullPath)
return allFiles
listOfFiles = getListOfFiles("./")
for file in listOfFiles:
if not file.endswith(".py"):
s = '"' + file.replace("./", "") + '",'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.