Files.WalkFileTree Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
WalkFileTree(IPath, IFileVisitor) |
Walks a file tree. |
WalkFileTree(IPath, ICollection<FileVisitOption>, Int32, IFileVisitor) |
Walks a file tree. |
WalkFileTree(IPath, IFileVisitor)
Walks a file tree.
[Android.Runtime.Register("walkFileTree", "(Ljava/nio/file/Path;Ljava/nio/file/FileVisitor;)Ljava/nio/file/Path;", "", ApiSince=26)]
public static Java.Nio.FileNio.IPath? WalkFileTree (Java.Nio.FileNio.IPath? start, Java.Nio.FileNio.IFileVisitor? visitor);
[<Android.Runtime.Register("walkFileTree", "(Ljava/nio/file/Path;Ljava/nio/file/FileVisitor;)Ljava/nio/file/Path;", "", ApiSince=26)>]
static member WalkFileTree : Java.Nio.FileNio.IPath * Java.Nio.FileNio.IFileVisitor -> Java.Nio.FileNio.IPath
Parameters
- start
- IPath
the starting file
- visitor
- IFileVisitor
the file visitor to invoke for each file
Returns
the starting file
- Attributes
Remarks
Walks a file tree.
This method works as if invoking it were equivalent to evaluating the expression: <blockquote>
walkFileTree(start, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, visitor)
</blockquote> In other words, it does not follow symbolic links, and visits all levels of the file tree.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
WalkFileTree(IPath, ICollection<FileVisitOption>, Int32, IFileVisitor)
Walks a file tree.
[Android.Runtime.Register("walkFileTree", "(Ljava/nio/file/Path;Ljava/util/Set;ILjava/nio/file/FileVisitor;)Ljava/nio/file/Path;", "", ApiSince=26)]
public static Java.Nio.FileNio.IPath? WalkFileTree (Java.Nio.FileNio.IPath? start, System.Collections.Generic.ICollection<Java.Nio.FileNio.FileVisitOption>? options, int maxDepth, Java.Nio.FileNio.IFileVisitor? visitor);
[<Android.Runtime.Register("walkFileTree", "(Ljava/nio/file/Path;Ljava/util/Set;ILjava/nio/file/FileVisitor;)Ljava/nio/file/Path;", "", ApiSince=26)>]
static member WalkFileTree : Java.Nio.FileNio.IPath * System.Collections.Generic.ICollection<Java.Nio.FileNio.FileVisitOption> * int * Java.Nio.FileNio.IFileVisitor -> Java.Nio.FileNio.IPath
Parameters
- start
- IPath
the starting file
- options
- ICollection<FileVisitOption>
options to configure the traversal
- maxDepth
- Int32
the maximum number of directory levels to visit
- visitor
- IFileVisitor
the file visitor to invoke for each file
Returns
the starting file
- Attributes
Remarks
Walks a file tree.
This method walks a file tree rooted at a given starting file. The file tree traversal is <em>depth-first</em> with the given FileVisitor
invoked for each file encountered. File tree traversal completes when all accessible files in the tree have been visited, or a visit method returns a result of FileVisitResult#TERMINATE TERMINATE
. Where a visit method terminates due an IOException
, an uncaught error, or runtime exception, then the traversal is terminated and the error or exception is propagated to the caller of this method.
For each file encountered this method attempts to read its java.nio.file.attribute.BasicFileAttributes
. If the file is not a directory then the FileVisitor#visitFile visitFile
method is invoked with the file attributes. If the file attributes cannot be read, due to an I/O exception, then the FileVisitor#visitFileFailed visitFileFailed
method is invoked with the I/O exception.
Where the file is a directory, and the directory could not be opened, then the visitFileFailed
method is invoked with the I/O exception, after which, the file tree walk continues, by default, at the next <em>sibling</em> of the directory.
Where the directory is opened successfully, then the entries in the directory, and their <em>descendants</em> are visited. When all entries have been visited, or an I/O error occurs during iteration of the directory, then the directory is closed and the visitor's FileVisitor#postVisitDirectory postVisitDirectory
method is invoked. The file tree walk then continues, by default, at the next <em>sibling</em> of the directory.
By default, symbolic links are not automatically followed by this method. If the options
parameter contains the FileVisitOption#FOLLOW_LINKS FOLLOW_LINKS
option then symbolic links are followed. When following links, and the attributes of the target cannot be read, then this method attempts to get the BasicFileAttributes
of the link. If they can be read then the visitFile
method is invoked with the attributes of the link (otherwise the visitFileFailed
method is invoked as specified above).
If the options
parameter contains the FileVisitOption#FOLLOW_LINKS FOLLOW_LINKS
option then this method keeps track of directories visited so that cycles can be detected. A cycle arises when there is an entry in a directory that is an ancestor of the directory. Cycle detection is done by recording the java.nio.file.attribute.BasicFileAttributes#fileKey file-key
of directories, or if file keys are not available, by invoking the #isSameFile isSameFile
method to test if a directory is the same file as an ancestor. When a cycle is detected it is treated as an I/O error, and the FileVisitor#visitFileFailed visitFileFailed
method is invoked with an instance of FileSystemLoopException
.
The maxDepth
parameter is the maximum number of levels of directories to visit. A value of 0
means that only the starting file is visited, unless denied by the security manager. A value of Integer#MAX_VALUE MAX_VALUE
may be used to indicate that all levels should be visited. The visitFile
method is invoked for all files, including directories, encountered at maxDepth
, unless the basic file attributes cannot be read, in which case the visitFileFailed
method is invoked.
If a visitor returns a result of null
then NullPointerException
is thrown.
When a security manager is installed and it denies access to a file (or directory), then it is ignored and the visitor is not invoked for that file (or directory).
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.