Rev | Line | |
---|
[0] | 1 | // spanDir - a directory traversal function for
|
---|
| 2 | // Rhino JavaScript
|
---|
| 3 | // Copyright 2010 by James K. Lawless
|
---|
| 4 | // See MIT/X11 license at
|
---|
| 5 | // http://www.mailsend-online.com/wp/license.php
|
---|
| 6 |
|
---|
| 7 | importPackage(java.io);
|
---|
| 8 |
|
---|
| 9 | // spanDir() accepts two parameters
|
---|
| 10 | // The first is a string representing a directory path
|
---|
| 11 | // The second is a closure that accepts a parameter of type
|
---|
| 12 | // java.io.File
|
---|
| 13 | function spanDir(dir,dirHandler) {
|
---|
| 14 | var lst=new File(dir).listFiles().sort(),
|
---|
| 15 | i;
|
---|
| 16 |
|
---|
| 17 | for(i=0;i<lst.length;i++) {
|
---|
| 18 | // If it's a directory, recursive call spanDir()
|
---|
| 19 | // so that we end up doing a scan of
|
---|
| 20 | // the directory tree
|
---|
| 21 | if(lst[i].isDirectory()) {
|
---|
| 22 | spanDir(lst[i].getCanonicalPath(),dirHandler);
|
---|
| 23 | }
|
---|
| 24 | // Pass the File object to the handler that
|
---|
| 25 | // the caller has specified regardless of whether
|
---|
| 26 | // the File object is a directory.
|
---|
| 27 | dirHandler(lst[i].getCanonicalPath());
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.