aspose file tools
The moose likes Beginning Java and the fly likes Finding CSV files in a directory? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Finding CSV files in a directory?" Watch "Finding CSV files in a directory?" New topic
Author

Finding CSV files in a directory?

Justin Filmer
Greenhorn

Joined: Jul 04, 2011
Posts: 27
Hi guys,

I'm having trouble understanding the FileVisitor class at http://download.oracle.com/javase/tutorial/essential/io/walk.html

Can someone show me how to find all of the source paths for all CSV files in "C:\MyFiles" and then invoke a method checkForCobalt(filepath) on each CSV file?

Thanks so much,
Justin
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi Justin,
I am unaware of the FileVistitor interface. Others would help you understand it.
Ok.... what you mean by source path for all csv files? is that the absolute path? and in which class checkForCobalt() method present? Is that your custom method.

Can you look the code above and tell where your requirement is missing

Welcome to the Ranch
Justin Filmer
Greenhorn

Joined: Jul 04, 2011
Posts: 27
That's ALMOST EXACTLY what I wanted! And the response was so quick... Thanks so much!
Thank you for the welcome as well!
I have two follow up questions...

1) Is there any special character that can be used to escape the '\' for the whole string?
What I mean is, instead of doing

Is there someway I can just do something like


2) How can the code be modified to go through all subdirectories to check for CSV files as well? For example, let's say "C:\Files" has two directories and two CSV files. In the subdirectory "C:\Files\Folders" there are five CSV files. How can I go through everything to find all seven CSV files?

Thanks so much! This is a great welcoming to the Ranch!
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Welcome!
You have to call the method recursively if you need to do that. I dont know if there is a string level escape. But the "/" works same as "\\".

Justin Filmer
Greenhorn

Joined: Jul 04, 2011
Posts: 27
Thank you very much! That's perfect. I wish there was a full-string escape, but Java doesn't seem to support it (I double checked). Looks like I'll have to go with the forward slash.

This has been great help, thanks so much John Jai!
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Ok. can you ask any specific question on the FileVistor interface you previously had. I think i stopped you learn a new thing.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Finding CSV files in a directory?
 
Similar Threads
How to read csv file & which collection should be used ?
File Issues
Not able to display Thai Characters
Most portable format for data
rading a .xls file file