Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

Java equivalent for MFC findnextfile

Thread view: 
jaja - 07 Aug 2007 08:18 GMT
Hello,
How can I iterate the files inside a directory, like FindNextFile in
Win32.
I don't want to use File.list() which returns me a list of all files.
Thanks.
Andrew Thompson - 07 Aug 2007 09:01 GMT
...
> How can I iterate the files inside a directory, like FindNextFile in
>Win32.

File.list() or File.listFiles() should provide a list you can iterate..

> I don't want to use File.list() which returns me a list of all files.

You poor thing.  Have you considered hiring someone to
code this for you?  I am guessing it will save you a lot of
stress.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Thomas Fritsch - 07 Aug 2007 10:29 GMT
>  How can I iterate the files inside a directory, like FindNextFile in
> Win32.
>  I don't want to use File.list() which returns me a list of all files.
Why not?

Signature

Thomas

jaja - 07 Aug 2007 12:24 GMT
On Aug 7, 12:29 pm, Thomas Fritsch <i.dont.like.s...@invalid.com>
wrote:
> >  How can I iterate the files inside a directory, like FindNextFile in
> > Win32.
[quoted text clipped - 4 lines]
> --
> Thomas

Because in case of a huge number of files, the list is very large and
memory consuming.
Do you know a way that I can iterate the files and get it one by one?
Thanks.
Andrew Thompson - 07 Aug 2007 12:51 GMT
>On Aug 7, 12:29 pm, Thomas Fritsch <i.dont.like.s...@invalid.com>
>wrote:
>> >  How can I iterate the files inside a directory, like FindNextFile in
>> > Win32.

(T.F.)
>> Why not?

>Because in case of a huge number of files, the list is very large and
>memory consuming.

Over optimisation.

>Do you know a way that I can iterate the files and get it one by one?

Implement a NextFileFilter that extends FileFilter and
feed it to File.listFiles(nextFileFilter).  But I expect the
JVM will ultimately fetch the entire file list before being
able to determine which is the 'next' file.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Christian - 07 Aug 2007 12:54 GMT
jaja schrieb:
> On Aug 7, 12:29 pm, Thomas Fritsch <i.dont.like.s...@invalid.com>
> wrote:
[quoted text clipped - 10 lines]
> Do you know a way that I can iterate the files and get it one by one?
> Thanks.

Are you really shure you need this kind of optimization?

usual directorys should have less than 10k files in them which should
mean less than 500 kiB of Memory, any problem with that?

if you have more than a 100k files per dir and need to have multiple
lists of such large directorys ..  well.. first I would recommend you to
check the program that produced these horrible mess of files as this
could crash your filesystem .. or at least give it a hard time.

Christian
Roedy Green - 07 Aug 2007 14:06 GMT
> How can I iterate the files inside a directory, like FindNextFile in
>Win32.
> I don't want to use File.list() which returns me a list of all files.

.list is the Java idiom.  It is probably considerably more efficient
to wind up the JNI .list method only once to get them all.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green - 07 Aug 2007 18:04 GMT
>.list is the Java idiom.  It is probably considerably more efficient
>to wind up the JNI .list method only once to get them all.

There is a considerable overhead crossing the blood-brain barrier into
the JNI world.  .list has to cross it only once.  findNextFile  would
have to cross it N times.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.