Java equivalent for MFC findnextfile

Discussion in 'Java' started by jaja, Aug 7, 2007.

  1. jaja

    jaja Guest

    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.
     
    jaja, Aug 7, 2007
    #1
    1. Advertising

  2. jaja wrote:
    ...
    > 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.

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

    Message posted via http://www.javakb.com
     
    Andrew Thompson, Aug 7, 2007
    #2
    1. Advertising

  3. jaja wrote:
    > 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?

    --
    Thomas
     
    Thomas Fritsch, Aug 7, 2007
    #3
  4. jaja

    jaja Guest

    On Aug 7, 12:29 pm, Thomas Fritsch <>
    wrote:
    > jaja wrote:
    > > 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?
    >
    > --
    > 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.
     
    jaja, Aug 7, 2007
    #4
  5. jaja wrote:
    >On Aug 7, 12:29 pm, Thomas Fritsch <>
    >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.

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

    Message posted via http://www.javakb.com
     
    Andrew Thompson, Aug 7, 2007
    #5
  6. jaja

    Christian Guest

    jaja schrieb:
    > On Aug 7, 12:29 pm, Thomas Fritsch <>
    > wrote:
    >> jaja wrote:
    >>> 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?
    >>
    >> --
    >> 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.
    >

    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
     
    Christian, Aug 7, 2007
    #6
  7. jaja

    Roedy Green Guest

    > 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.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Aug 7, 2007
    #7
  8. jaja

    Roedy Green Guest

    >.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.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Aug 7, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott McPhillips
    Replies:
    0
    Views:
    395
    Scott McPhillips
    Jul 5, 2003
  2. ringos75
    Replies:
    0
    Views:
    987
    ringos75
    Apr 14, 2005
  3. yopwojtek

    Derive from MFC DLL to MFC APP

    yopwojtek, Aug 6, 2005, in forum: C++
    Replies:
    1
    Views:
    395
    Alf P. Steinbach
    Aug 6, 2005
  4. Masao Kishore

    findFirstFile, findNextFile

    Masao Kishore, Aug 18, 2005, in forum: C++
    Replies:
    2
    Views:
    882
    Srini
    Aug 18, 2005
  5. prakasha

    FindNextfile not working properly

    prakasha, Mar 22, 2011, in forum: C Programming
    Replies:
    0
    Views:
    434
    prakasha
    Mar 22, 2011
Loading...

Share This Page