Class RemoteDirectoryListing
RemoteFile.list(): set the
filters, then collect the result with execute() or stream it with stream().
RemoteFileList logs = client.file("C:\\inetpub\\logs")
.list()
.glob("*.log")
.recursive()
.filesOnly()
.modifiedAfter(Instant.now().minus(Duration.ofDays(1)))
.execute();
The directory is walked on the host by a small PowerShell script, and every filter is
evaluated there: only the matching entries travel. Without recursive(), only the
directory's own entries are listed. With it, every subdirectory is traversed — whatever the
filters, which select what is reported, not where the walk goes — except reparse points
(junctions, symbolic links, mount points), which are reported but never descended into, so a
junction looping back to its parent terminates. A subdirectory that cannot be read (typically
access denied) does not stop the walk: its path is reported through
onInaccessible(Consumer) and RemoteFileList.inaccessible().
A request is not thread-safe; configure it and call its terminals from one thread.
-
Method Summary
Modifier and TypeMethodDescriptionReport directories only.execute()List the directory and collect the result.Report files only (directories are still traversed withrecursive()).Report only the entries whose name (not path) matches the given Windows wildcard pattern:*matches any sequence of characters (including none),?exactly one character, and every other character only itself, case-insensitively.maxDepth(int maxDepth) List recursively, down to the given depth: 1 is the directory's own entries (the same as a non-recursive listing), 2 adds the entries of its subdirectories, and so on.maxSize(long bytes) Report only the files of at most the given size.minSize(long bytes) Report only the files of at least the given size.modifiedAfter(Instant instant) Report only the entries last modified strictly after the given instant.modifiedBefore(Instant instant) Report only the entries last modified strictly before the given instant.onInaccessible(Consumer<String> consumer) Be told of each directory that could not be read (typically access denied): its path is given to the consumer as soon as the host reports it, and the walk goes on.List the whole tree below the directory instead of its own entries only, depth-first.stream()List the directory and stream the entries as the host reports them: memory stays bounded whatever the size of the tree.Override the client's timeout for this request.
-
Method Details
-
glob
Report only the entries whose name (not path) matches the given Windows wildcard pattern:*matches any sequence of characters (including none),?exactly one character, and every other character only itself, case-insensitively. The whole name must match:*.logmatchesapp.log, notapp.log.1(unlikedir, which also matches 8.3 short names). Withrecursive(), every directory is still traversed; the pattern only selects what is reported.- Parameters:
glob- the pattern, e.g.*.logoru_ex??????.log- Returns:
- this request
-
recursive
List the whole tree below the directory instead of its own entries only, depth-first. Reparse points are reported but never descended into.- Returns:
- this request
-
maxDepth
List recursively, down to the given depth: 1 is the directory's own entries (the same as a non-recursive listing), 2 adds the entries of its subdirectories, and so on. Impliesrecursive().- Parameters:
maxDepth- the deepest level listed (at least 1)- Returns:
- this request
-
filesOnly
Report files only (directories are still traversed withrecursive()). ReplacesdirectoriesOnly().- Returns:
- this request
-
directoriesOnly
Report directories only. ReplacesfilesOnly().- Returns:
- this request
-
modifiedAfter
Report only the entries last modified strictly after the given instant.- Parameters:
instant- the exclusive lower bound- Returns:
- this request
-
modifiedBefore
Report only the entries last modified strictly before the given instant.- Parameters:
instant- the exclusive upper bound- Returns:
- this request
-
minSize
Report only the files of at least the given size. Directories have no size and are not filtered by it: combine withfilesOnly()to leave them out.- Parameters:
bytes- the smallest size, inclusive- Returns:
- this request
-
maxSize
Report only the files of at most the given size. Directories have no size and are not filtered by it: combine withfilesOnly()to leave them out.- Parameters:
bytes- the largest size, inclusive- Returns:
- this request
-
onInaccessible
Be told of each directory that could not be read (typically access denied): its path is given to the consumer as soon as the host reports it, and the walk goes on. Applies to both terminals;execute()also collects the paths inRemoteFileList.inaccessible(). The directory being listed is not concerned: when it cannot be read, the listing fails.- Parameters:
consumer- receives the path of each directory that could not be read- Returns:
- this request
-
timeout
Override the client's timeout for this request. Forexecute()it is a wall-clock deadline for the whole listing; forstream()it is an inactivity timeout. The host signals it is alive every second while it walks, so the inactivity timeout only trips when the host is unresponsive — or when reading a single directory takes longer.- Parameters:
timeout- the timeout (at least one millisecond)- Returns:
- this request
-
execute
List the directory and collect the result.- Returns:
- the matching entries and the directories that could not be read
- Throws:
WinRMClientException- when the directory cannot be listed (not found, a file, access denied, PowerShell unavailable or constrained)WinRMTimeoutException- when the timeout elapses first
-
stream
List the directory and stream the entries as the host reports them: memory stays bounded whatever the size of the tree.try (Stream<RemoteFileInfo> tree = client.file("D:\\data").list().recursive().stream()) { tree.filter(RemoteFileInfo::isDirectory).forEach(System.out::println); }The stream must be closed — use try-with-resources. It holds the client's connection until it is exhausted or closed; closing it early stops the remote walk. The listing starts here, and the failures below are thrown from the stream's operations, when the host reports them. The timeout is an inactivity timeout (see
timeout(Duration)).- Returns:
- a lazy, sequential stream of entries, to use with try-with-resources
- Throws:
WinRMClientException- when the directory cannot be listedWinRMTimeoutException- when the host does not answer in time
-