listFiles

listFiles ( string path , boolean[default:false] _returnCompletePath , boolean[default:false] _includeSubFolders , boolean[default:all] _filesAndDirs ) : string[]

List files in a folder. Returns an array of filenames (name of the file + extension).


Example


files = listFiles(path("desktop")+"/myFolder/")
console(files) //-> ["file1.png", "file2.pdf"]
files.each{ file->
console("Path is "+path("desktop")+"/myFolder/"+file)
}


Use Java File objects :
files = listFiles(path("desktop")+"/myFolder/", true)
files.each{ path->
nameParentFolder = new File(path).getParentFile().getName()
console("The name of the parent folder of "+path+" is "+nameParentFolder)
}

Parameters

path

path of the folder where are files to list

_returnCompletePath (optional)

If true, it returns the complete path. Else, it is just the file name.

_includeSubFolders (optional)

If true, it returns files in sub-folders. Else, it is just the files in the indicated folder

_filesAndDirs (optional)

By default, it returns files and folders. If you filesAndDirs="files", it returns just files. If filesAndDirs="directories", it returns just folders.