Posted on Leave a comment

Use Python To List All Files In A Directory

I needed a lengthy list of files for a massive 3D printing project I’m starting and I didn’t want to have to copy and paste each file one at a time.  Brandon’s Rule #232:  If you are faced with a 2 minute task that bores the hell out of you, invest 15 minutes into automating it.

Everyone should have Sublime Text installed on their machine and have just enough competence in Python to Google the living crap out of any problem that arises.

This Python code simply lists all the files in the directory containing this file.


from os import listdir
from os.path import isfile, join

mypath = '.'
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

for x in range(len(onlyfiles)):
print(onlyfiles[x])
Leave a Reply

Your email address will not be published. Required fields are marked *