mookie13
asked on
Read directory contents and output in in JSP page
Hi all,
I have several directories of static images and swf files. I want to build a JSP that reads the files, by file type, and renders the images/swf's on the output page. I'd also like to sort by date or file name. Make sense?
I can do this in Perl pretty easily like this:
$dirtoget="/home/www/site/ ";
opendir(IMD, $dirtoget) || die("Cannot open directory");
Then dump into an array:
@thefiles= readdir(IMD);
From there I could output however I wanted. Not sure how to do this in JSP. Help please... :)
I have several directories of static images and swf files. I want to build a JSP that reads the files, by file type, and renders the images/swf's on the output page. I'd also like to sort by date or file name. Make sense?
I can do this in Perl pretty easily like this:
$dirtoget="/home/www/site/
opendir(IMD, $dirtoget) || die("Cannot open directory");
Then dump into an array:
@thefiles= readdir(IMD);
From there I could output however I wanted. Not sure how to do this in JSP. Help please... :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is great!!! I was just now able to get back to this project. Appreciate your help!!
String the_path = "/home/www/site/";
File theDir = new File(the_path);
String[] theDirectoryFiles = theFile.list();
for(int i=0; i<theDirectoryFiles.length
File theFile = new File(thePath + "//" + theDirectoryFiles[i]);
//this file can then be printed out or whatever.
}