Deokie
0
Q:

get the names of all files in a folder

List<String> results = new ArrayList<String>();


File[] files = new File("/path/to/the/directory").listFiles();
//If this pathname does not denote a directory, then listFiles() returns null. 

for (File file : files) {
    if (file.isFile()) {
        results.add(file.getName());
    }
}
2
import glob
print(glob.glob("/home/adam/*.txt"))
8
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
2
In MS Windows it works like this:

1. Hold the "Shift" key, right-click the folder containing the files and select "Open Command Window Here."

2. Type "dir /b > filenames.txt" (without quotation marks) in the Command Window. Press "Enter."

3. Inside the folder there should now be a file filenames.txt containing names of all the files etc. inside this folder.

4. Copy and paste this file list into your Word document.
0

New to Communities?

Join the community