Skip to content

Instantly share code, notes, and snippets.

@heiswayi
Created December 31, 2019 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heiswayi/7be7f5b6d7fc5ddede1ad36ab209aa76 to your computer and use it in GitHub Desktop.
Save heiswayi/7be7f5b6d7fc5ddede1ad36ab209aa76 to your computer and use it in GitHub Desktop.
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)
else:
allFiles.append(fullPath)
return allFiles
listOfFiles = getListOfFiles("./")
for file in listOfFiles:
if not file.endswith(".py"):
s = '"' + file.replace("./", "") + '",'
print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment