View Full Version : Loading Filenames into a Dynamic Array?

06-05-2008, 05:45 PM
I made a simple bit of code to randomly pick and display a picture every few minutes, for my windows desktop, as seen here:

function background()
var background = (abs(round(random()*10000)))
background = background % 2;
background +=1;
element.runtimeStyle.background = "url("+background+".jpg) fixed";
setTimeout( "window.location.reload()", 300000 );

Now, that's all very well, but it's a bit inconvenient, since I have to number all my files 1,2,3, and adjust the code everytime I aquire a new picture.

It's been several years since I've done any type of programming, but is there a way I can load the files, for a directory (and possibly the sub-directories) into a Dynamic Array, and get the length of the Array, and how would I do it?

06-06-2008, 12:03 AM
try something like

import java.io.*


File dir = new File("images"); // Your image directory
File[] files = dir.listFiles(); // You'll need to check to make sure the file object isn't a directory, see javadocs for java.io.File

Also you can make another class that implements FilenameFilter or FileFilter and pass a filter into listFiles or list.

hope this helps.

semper fi...

06-07-2008, 08:39 AM
Thanks, it's helped me a bit, I'm still very rusty, but it should take me long to get back into the swing of things.

06-08-2008, 06:02 PM
Hi Zem...
Hey man since ur coding now maybe u can look at the players stats page on the mojo site and help us with the coding...We want to add buttons to increase or decrease the size of the gif but keep the win loss percentage aspect of the scripts...
That is IF your the DR2 ZEM MASTER:thumbsup:

01-27-2009, 02:21 PM
Hi Zemzerrett,

Have you got any final solution. I want to implement a similar solution. i am creating a vista gadget in which in the flyout...i want to display some images stored on server and after that i want to display those images randomly.

Can you give me the entire javascript if possible