View Full Version : Use Java to list files in a directory and then full into an iframe>

02-02-2012, 10:49 PM
Hello and thank you in advance for your time!
I am building a page that will display a file in an iframe.
The problem is that the files won't necessarily be static.
We are collecting weather data at 1 min. intervals which is saved into a flat file. I will be uploading these files (and re-uploading at set intervals) into a set directory with a naming scheme of Feb12log.* (type of file doesn't really matter. could be .txt, .csv, .xls) but the name will change corresponding with the month & year: {MMM}{DD}log.{ext}. Each month, a new file is created
I can successfully pull a file into an iframe. I can build a drop box and a static list of files (File1, File2, File3 etc). I am pretty sure that I can build a search box in the page that will parse the information in the iframe (Ctrl+F would work as well I guess). Hopefully this is enough background info.
Instead of building a page for each new month ad nauseam, I would love to be able to pull a list of files currently in the upload directory into a dropdown box and when a file is selected, have it display in an iframe on the same page. The ability to be able to search the page would be awesome.

I am not looking for a handout, and I appreciate any input at all. My questions are: 1. Is this possible? Or should I resign myself to manually creating new pages every month? 2. Would anyone be able give me a nudge in the correct direction?
Thanks again!

02-03-2012, 08:44 PM
So I can pull a drop down from an array:

<script language="javascript">

function optionSel(selectbox,text,value )
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;

function Option_list(selectbox){
var month = new Array("Jan12","Feb12","Mar12","Apr12","May12","Jun12","Jul12","Aug12","Sep12","Oct12","Nov12","Dec12");
for (var i=0; i < month.length;++i){

optionSel(document.drop_list.Month_list, month[i], month[i]);

<body onLoad="Option_list()";>
<FORM name="drop_list" action="yourpage.php" method="POST" >

<SELECT NAME="Month_list">
<Option value="" >Month list</option>

And I have figured out how to pull multiple links into a target iFrame:

<TITLE>Site Current Month Totals</TITLE>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<TD><H4>Monthly Totals</H4>

<LI><A HREF="Jan12log.txt" TARGET="DisplayWindow">Document 1</A>
<LI><A HREF="Feb12log.txt" TARGET="DisplayWindow">Document 2</A>
<LI><A HREF="Mar12log.txt" TARGET="DisplayWindow">Document 3</A>

WIDTH=1024 HEIGHT=480>


Does anyone have an idea for code for a recursive search that can read a directory into an array? It could be a server side script.
If I can figure that out, and figure how to tie it all together, the only thing left is to format the directory list as links and it should be good.
Again, I would be very thankful for any tips.

02-07-2012, 02:35 PM
I apologize for the bump.

02-07-2012, 06:21 PM
Are you sure your language in use here is Java? all of the code you have here is Javascript and the processing language is PHP. If the file scan is on the server, this given the code you have, would be a PHP task. If its local, it would be Javascript, but I don't know what type of control there is in place to prevent iteration of filesystem (I'd guess that it would be denied local).

If its Java, I'm not sure how much help you'll find here. Unfortunately, I'm am probably among the more versed in JSP, and I haven't used it in over 6 years with no intention of ever touching it again.

02-07-2012, 07:05 PM
That was a mistype in the title.
Truly, I am not picky on what language or process that is used to get the desired results. Thus far I am just piecing together snippets that I have found on the web.
The restraints can be as liberal as needed. (it is a local iis 7 server on an intranet, which is used to display weather data) Although I would like to keep close to best practice on the security side, I am willing to loosen as needed to get this done.
Any thoughts on how it might be accomplished (in any language)?
Thank you in advance.

02-07-2012, 09:58 PM
Pretty much any language is capable of scanning a directory. Reading on a client cannot be done without a client language, and reading from a server takes a server language. I'd bet that JS itself could not read the filesystem of the client. Java itself can have an app written to perform this task. If its already on the server, then your processing language there would scan and show as necessary.
Web processing languages job is to dynamically generate content from either changing information or from user input. So sure you can set this up to do what you want. But you do need to choose the language you are planning to use first; JSP requires a JSP compatible server, ASP.NET would require IIS, PHP is pretty much fair game anywhere as is Perl. All of these languages can iterate a directory and choose files if you provide it something to compare against so long as they are on the server itself.