I am using the python plugin for notepad ++ and need to be able to get a printout of all the files in a directory. Basically I need to run something like dir in command prompt.
Is there any way to do this?
I am using the python plugin for notepad ++ and need to be able to get a printout of all the files in a directory. Basically I need to run something like dir in command prompt.
Is there any way to do this?
You can use the os.listdir()
function to get a list of the files in a directory.
So, here's how to put all the files in a directory and in all its sub-directories in a list, print out the list.
Note: How to 'walk' was found here:
concatenate the directory and file name
# Task: Get a printout of all the files in a directory.
import os
# The directory that we are interested in
myPath = "/users/george/documents/"
# All the file paths will be stored in this list
filesList= []
for path, subdirs, files in os.walk(myPath):
for name in files:
filesList.append(os.path.join(path, name))
for i in filesList:
print (str(i))