• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I get dir.list() to ignore directories  RSS feed

 
Reggie McDougal
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only want to look at files can any one give me an idea of how to aviod this?



CODE]

File dir = new File(myPath);

String[] contents = dir.list();[

[/CODE]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't make list() ignore directories, but when you look at the contents of the array, you can use File.isDirectory() to check for them and ignore them yourself.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However you can make listFiles(FileFilter) ignore directories:

Which isn't really any better than what EFH suggested; just another alternative.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!