Questions tagged [directorystream]
16 questions
44
votes
9 answers
Recursively list all files within a directory using nio.file.DirectoryStream;
I want to list all the FILES within the specified directory and subdirectories within that directory. No directories should be listed.
My current code is below. It does not work properly as it only lists the files and directories within the…

Danny Rancher
- 1,923
- 3
- 24
- 43
4
votes
1 answer
DirectoryStream return path in what kind of order? filename, last modified, filesize?
I am trying to read multiple files in a folder using DirectoryStream. There are 10 items altogether.
doc_01.txt, doc_02.txt, doc_03.txt, doc_04.txt, doc_05.txt, doc_06.txt, doc_07.txt, doc_08.txt, doc_09.txt, doc_10.txt
I wanted the file to be…

udon
- 93
- 1
- 5
3
votes
3 answers
List all Files from a Directory that match a File Mask (a.k.a Pattern or Glob)
I want to list all files in a directory and subdirectories within that directory that match a file mask.
For example "M:\SOURCE\*.doc" while SOURCE may look like this:
|-- SOURCE
| |-- Folder1
| | |-- File1.doc
| | |-- File1.txt
| |--…

Jeyson Ardila
- 43
- 7
2
votes
2 answers
List directory content with Project Reactor and DirectoryStream
I'd like to use DirectoryStream with Project Reactor to list all the files in a directory.
My try is:
Path myDir = Paths.get("C:\\Users\\r.dacanal\\Documents\\Reply\\EDA\\logging-consumer\\input");
DirectoryStream directoryStream =…

dacanalr
- 183
- 2
- 14
2
votes
1 answer
In Java 8 Stream API, what's the difference between a DirectoryStream and Stream?
I want to return a stream of paths (these are files located in a certain directory). My initial approach was this:
DirectoryStream getFiles(Path dir) throws IOException {
Files.newDirectoryStream(dir);
}
... but, I would like to know the…

Chthonic Project
- 8,216
- 1
- 43
- 92
1
vote
2 answers
Java - Count all file extensions in a folder using DirectoryStream
I would like to show all file extensions in a specific folder and give the total for each extension using DirectoryStream.
Now I'm only showing all the files in that folder, but how do I get their extensions only instead?
I should also get the…

Sitjuh
- 107
- 8
1
vote
0 answers
Directly read a specific subdirectory from a zip file [Java]
I would like to directly read the files from a subdirectory which is in a zip file.
Is there a more convenient way to do it without iterating through all entries?
The structure of the zip file is always the same, only the files in the subdirectory…

nikolakoco
- 1,343
- 1
- 12
- 22
1
vote
1 answer
How to use Java's directory stream to get files/subdirectories only within directory not other subdirectories
I'm using Java's DirectoryStream to get a list of all the files/subfolders in a directory. However, after going through all the files and folders of the directory, my code then proceeds to go through all the subdirectories. How can I stop it from…

Brandan B
- 464
- 2
- 6
- 21
1
vote
3 answers
How does "try-with-resources" actually work in the context of this program that deletes all files and folders below a given directory node
This program deletes all files and folders beneath a given node.
*EDIT*
I have the following "test" directory structure on drive K:
Folder K:\garbage\
f_00000b (file)
f_00000f ( " )
f_0000b3 ( " )
dir1 [FOLDER]
Folder K:\garbage\dir1\
abc.pdf…

DSlomer64
- 4,234
- 4
- 53
- 88
0
votes
1 answer
Copying multiple files from one folder to another in JAVA 15
Path src = Paths.get("./resources");
Path dst = Paths.get("./trash");
try {
DirectoryStream ds = Files.newDirectoryStream(src);
for(Path fileorDir : ds) {
…

Fugazzie
- 13
- 2
0
votes
1 answer
Java NIO Read Folder's content's attributes at once
I'm writing a backup program using Java and the package NIO.
As far as I found, I could do it as in the code example below, i.e. read the folder content list and then for each file I have to do file attributes request... this is not an effective…

Sunny
- 83
- 1
- 7
0
votes
1 answer
How to calculate number of documents per hour depending on their "last modified"
I'm working on a tool to count archived files from another program. Therefor I'm using the DirectoryStream and filter subdirectories and some files with a simple if-clause (shown below).
For the statistics I would like to know, how many documents…

T_Ix
- 66
- 8
0
votes
1 answer
Java FileVisitor visit ordered in a directory
I am trying to use the Java's FileVisitor interface to walk through a list of files and import the contents onto a database. The scenario is to import the csv contents in order. There may be a file with name Object.csv, Object_updated.csv,…

dmachop
- 824
- 1
- 21
- 39
0
votes
0 answers
Java on Macintosh directoryStream shows Applications as Folders
I feel like I must be missing something. It seems like this should be really easy but I can't seem to find an answer to this question.
I'm writing code in Java 8 using both
Files.newDirectoryStream()
class SimpleFileVisitor() {}
On a Macintosh…

backtocoding
- 71
- 7
0
votes
0 answers
Deleting empty folders in Java, dealing with hidden files
I am trying to delete empty folders in java, here is my code:
try (DirectoryStream stream = Files.newDirectoryStream(path)) {
for (Path file : stream) {
if (file.toFile().isFile()) {
…

jogorm
- 33
- 1
- 6