Skip to content

Commit 1594573

Browse files
committed
fix directory list example #460
1 parent bcc24eb commit 1594573

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

content/examples/Topics/File IO/DirectoryList/DirectoryList.pde

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import java.util.Date;
1414

1515
void setup() {
1616

17-
// Path
18-
String path = sketchPath;
17+
// Using just the path of this sketch to demonstrate,
18+
// but you can list any directory you like.
19+
String path = sketchPath();
1920

2021
println("Listing all filenames in a directory: ");
2122
String[] filenames = listFileNames(path);
22-
println(filenames);
23-
23+
printArray(filenames);
24+
2425
println("\nListing info about all files in a directory: ");
2526
File[] files = listFiles(path);
2627
for (int i = 0; i < files.length; i++) {
@@ -32,11 +33,11 @@ void setup() {
3233
println("Last Modified: " + lastModified);
3334
println("-----------------------");
3435
}
35-
36+
3637
println("\nListing info about all files in a directory and all subdirectories: ");
3738
ArrayList<File> allFiles = listFilesRecursive(path);
38-
39-
for (File f: allFiles) {
39+
40+
for (File f : allFiles) {
4041
println("Name: " + f.getName());
4142
println("Full path: " + f.getAbsolutePath());
4243
println("Is directory: " + f.isDirectory());
@@ -52,7 +53,6 @@ void setup() {
5253
// Nothing is drawn in this program and the draw() doesn't loop because
5354
// of the noLoop() in setup()
5455
void draw() {
55-
5656
}
5757

5858
// This function returns all the files in a directory as an array of Strings
@@ -82,9 +82,9 @@ File[] listFiles(String dir) {
8282

8383
// Function to get a list of all files in a directory and all subdirectories
8484
ArrayList<File> listFilesRecursive(String dir) {
85-
ArrayList<File> fileList = new ArrayList<File>();
86-
recurseDir(fileList,dir);
87-
return fileList;
85+
ArrayList<File> fileList = new ArrayList<File>();
86+
recurseDir(fileList, dir);
87+
return fileList;
8888
}
8989

9090
// Recursive function to traverse subdirectories
@@ -96,9 +96,9 @@ void recurseDir(ArrayList<File> a, String dir) {
9696
File[] subfiles = file.listFiles();
9797
for (int i = 0; i < subfiles.length; i++) {
9898
// Call this function on all files in this directory
99-
recurseDir(a,subfiles[i].getAbsolutePath());
99+
recurseDir(a, subfiles[i].getAbsolutePath());
100100
}
101101
} else {
102102
a.add(file);
103103
}
104-
}
104+
}

0 commit comments

Comments
 (0)