Hi,
I am trying to build a gui using java that allows the user to go thru
filechooser and pick any file(s) and/or directories. If a file or files
are chosen then the names of the files are appended to a list. If a
directory is chosen then the names of all the files in the directory
should be appended to the list.
I already have most of this code written up. However the code I have
does not distinguish between a file and a directory so it doesn't know
to open the directory. I was hoping there might be some built in
function that would determine this for me but I can't seem to find it.
I am still very new to Java and am trying to teach myself. Any help
would be appreciated.
Matt Humphrey - 24 Jun 2005 15:20 GMT
> Hi,
>
[quoted text clipped - 11 lines]
> I am still very new to Java and am trying to teach myself. Any help
> would be appreciated.
You will want to check out the File API. Look for isDirectory ().
Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/
Fahd Shariff - 27 Jun 2005 15:42 GMT
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File[] files = chooser.getSelectedFiles() ;
for(int i = 0 ; i < files.length ; i++){
File f = files[i] ;
if(f.isDirectory()){
String[] filenames = f.list() ;
//append to your list
}
else{
//append f to your list
}
}
}
--
Fahd Shariff
http://www.fahdshariff.cjb.net
"Let the code do the talking... "