Skip to content

Instantly share code, notes, and snippets.

@kirkbyo
Last active August 29, 2015 14:28
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 kirkbyo/55d88fbca3d678ca8307 to your computer and use it in GitHub Desktop.
Save kirkbyo/55d88fbca3d678ca8307 to your computer and use it in GitHub Desktop.
Writes all files that end with a certain extentsion to a .txt file
import os
# Writes all files that end with a certain extentsion to a .txt file
# Works in both Python 2 and Python 3
extension = ".png"
fileList = os.listdir('Outflow-Icons')
for fichier in fileList[:]: # filelist[:] makes a copy of filelist.
if not(fichier.endswith(extension)):
fileList.remove(fichier)
textFile = open("output.txt", "w")
for item in fileList:
textFile.write('"{}",\n'.format(item))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment