• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding CSV files in a directory?  RSS feed

 
Justin Filmer
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. can you ask any specific question on the FileVistor interface you previously had. I think i stopped you learn a new thing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!