• Post Reply Bookmark Topic Watch Topic
  • New Topic

List all files from a drive

 
Smilidon Sapiens
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I try to write all file(names) from a drive into a vector.
Code:
<Code>
public static Vector listFilez(File tree) throws IOException
{
Vector endAll = new Vector();
File[] files = tree.listFiles();
for (int i = 0; i < files.length; i++)
{
String fileName = files[i].getName();
if (files[i].isFile())
{
if (fileName.endsWith(".ini"))
{
endAll.addElement(files[i]);
}
}
if (files[i].isDirectory())
{
listFilez(files[i]);
}
} return endAll;
}
</Code>
My Problem is: I get only the files from the parent directory. Can you help me, please? I don't know, what I did wrong ...
Thanks!
 
Smilidon Sapiens
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solvd it!
I don't know how it works with the return statement, I use a parameter vector...
<code>
public static void listFilez(File tree, Vector endAll) throws IOException
{
File[] files = tree.listFiles();
for (int i = 0; i < files.length; i++)
{
String fileName = files[i].getName();
if (files[i].isFile())
{
// if (fileName.endsWith(".ini"))
{
endAll.addElement(files[i]);
}
}
if (files[i].isDirectory())
{
listFilez(files[i], endAll);
}
}
}
</code>
Please write your solution, too!
Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!