Created
December 31, 2019 16:13
-
-
Save heiswayi/7be7f5b6d7fc5ddede1ad36ab209aa76 to your computer and use it in GitHub Desktop.
Python script for getting a list of files in a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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