Random file selection

G

Guest

I'm trying to think of a way to select random unknown files from a known
root folder. The files are randomly in sub-folders and sub-sub folders, etc
which I would like to try to select on a fairly arbitrary basis. Is there
any random recursive way to select files from a root folder in the way I'm
trying?

TIA
 
P

Piotr Pejas

Hello,
Simple method to read all files in direcory with subdirectories can be
implemented in this way:

public void readDirectory( String directoryPath ) throws Exception {
addDirectory( new File( directoryPath ) );
}
private void addDirectory( File file ) throws Exception {
if( file.isDirectory() ) {
for( File f : file.listFiles() ) {
addDirectory( f );
}
}
else {
addFile( file );
}
}
You have to implement addFile( File file ); method.

Best Regards
Piotr Pejas


--
Piotr Pejas
Java devleloper
Yumasoft sp. z o. o
www.yumasoft.pl
tel. +4871 78 44 123

(e-mail address removed) napisal(a):
 

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
474,270
Messages
2,571,102
Members
48,773
Latest member
Kaybee

Latest Threads

Top