• Post Reply Bookmark Topic Watch Topic
  • New Topic

Folder traverse from a location  RSS feed

 
Mohan Vinukonda
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've got a requirement that I need to traverse folder and read files inside. I've given a location using some date range. All folder files names would get store with file name as date as YYYY-MM-DD. I need traverse those folders and read files. Can any one of you please through some light on it. Thanks in advance!
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The File class is your friend.
Check out the list method in the File class.
You will need recursion to traverse down the hierarchy.

Are you stuck at traversing or reading the files?
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Check out the list method in the File class.

Or even better, listFiles. That one returns a File[] instead of a String[]. Also check out the use of java.io.FileFilter or java.io.FilenameFilter as arguments of listFiles.
 
Vivek K Singh
Ranch Hand
Posts: 85
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File class represents files as well as directories, Do something like this:

 
Mohan Vinukonda
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your response,
I am stuck with folder traversing, I have list of folders having name as date. If the user gives date range I need to traverse all the folders falling under date range and also subfolders. there I need to read .xml file and create some other xml file.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, if the answers above didn't answer your question, then please explain in more detail where you are stuck.

Did you write some code yourself already? Does it not work? What exactly are you having problems with?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(There are also Apache Commons classes that do directory/file recursion, although I don't remember them at the moment.)
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Rob mentioned, you would have to use java.io.FileFilter or java.lang.FileNameFilter.
In the filter check if the filenames are within the boundary dates you want and then filter the list based on it. You would also need to parse the string to a date. Check out java.lang.SimpleDateFormat class as well.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!