Official Documentation: http://docs.groovy-lang.org/latest/html/groovy-jdk/java/io/File.html
Common Method:
1. Eachfile (file self, Closure Closure): Invokes the Closure for each "child" File or directory in this ' parent ' folder /directory.
Class Eachdirtest {public
static void Main (string[] args) {
def dir = new File ("D:\\project\\soapui\\project-smo Ke-tests ")
dir.eachfile{file-
println file
}
}
2. Eachfile (file Self, FileType FileType, Closure Closure): Invokes the Closure for each "child" file or directory in This ' parent ' folder/directory.
Param FileType is an Enum:
Any:represents both normal files and directories
Directories:represents Directories
files:represents Normal Files
Import Groovy.io.FileType
class Eachdirtest {public
static void Main (string[] args) {
def dir = new File ("D:\ \project\\soapui\\project-smoke-tests ")
//only output The normal files
dir.eachfile (filetype.files) {file- >
println file
}
}
}
3. Eachfilematch (file Self, FileType FileType, Object namefilter, Closure Closure): Invokes the Closure for each File Whose name (File.name) matches the given namefilter in the given directory-calling the Iscase (Java.lang.Object, Java.lan G.object) method to determine if a match occurs.
Import Groovy.io.FileType
class Eachdirtest {public
static void Main (string[] args) {
def dir = new File ("D:\ \project\\soapui\\project-smoke-tests\\healthall ")
//only output The normal files
dir.eachfilematch ( Filetype.files, ~/^data.*/) {file,
println file
}
}
}
4. Eachfilematch (file Self, Object namefilter, Closure Closure): Invokes the Closure for each File whose name (file.na Me) matches the given namefilter in the given directory-calling the Iscase (Java.lang.Object, Java.lang.Object) method to Determine if a match occurs.
Import Groovy.io.FileType
class Eachdirtest {public
static void Main (string[] args) {
def dir = new File (" D:\\project\\soapui\\project-smoke-tests ")
Dir.eachfilematch (~/^sanity.*/) {file--
println file
}
}
}
5. Eachfilerecurse (file self, Closure Closure): Invokes the Closure for each descendant File and directory in this dir Ectory.
Import Groovy.io.FileType
class Eachdirtest {public
static void Main (string[] args) {
def dir = new File ("D:\ \project\\soapui\\project-smoke-tests ")
dir.eachfilerecurse{file-
println file
}
}
6. Eachfilerecurse (file Self, FileType FileType, Closure Closure): Invokes the Closure for each descendant File in thi S directory.
Import Groovy.io.FileType
class Eachdirtest {public
static void Main (string[] args) {
def dir = new File (" D:\\project\\soapui\\project-smoke-tests ")
//only output The normal files
dir.eachfilerecurse ( Filetype.files) {file,
println file
}
}
}