directory and folders

P

polilop

I need to traverse through a directory,which inside has a directory and
files. I need to save the directory name and files which are inside, to an
array, something like
Array [dirName][fileName] so i can print them out later something like
dirName
fileName
fileName1
dirName1
fileName
fileName1.
(they will be hyperlinks to files)
I have solved the problem of goining into a directory and getting the files
and other directories with a recursive funcition. My problem is how to store
the directory and file names, especially into an array as i dont allways
know how big my array could be.
Thanks in advanced

my recursive function.

public void doTest9( String path)
{

String mainDir = path;

File dir = new File(mainDir);

File[] files = dir.listFiles();

for(int i = 0; i < files.length ; i++)
{
if(files.isDirectory())
{
doTest9(path+"\\"+files.getName()+"\\");
}
}

}
 
J

Joshua Cranmer

polilop said:
I need to traverse through a directory,which inside has a directory and
files. I need to save the directory name and files which are inside, to an
array, something like
Array [dirName][fileName] so i can print them out later something like
dirName
fileName
fileName1
dirName1
fileName
fileName1.
(they will be hyperlinks to files)
I have solved the problem of goining into a directory and getting the files
and other directories with a recursive funcition. My problem is how to store
the directory and file names, especially into an array as i dont allways
know how big my array could be.

ArrayList works fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top