Thread: How to get names of folders in specific folder

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    241

    How to get names of folders in specific folder

    How can I get the name of folders in a specific folder and the number of folders in that specific folder?
    and then cycle through them?
    Last edited by bikr692002; 09-04-2006 at 01:56 PM.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Yeah but I don't know the name of the folder and that faq requires one to search for =\

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Sorry, I misread your question. (Or maybe it was edited.)

    You coould use the directory walker to find the names of the files and directories. Then you could try chdir()ing to each one to see if it's a directory. Or you could use stat/fstat to see if it is a directory. (chdir() and fstat() are part of the POSIX standard.) [edit] stat might be best: http://www.gnu.org/software/libc/man...ttributes.html [/edit] [edit=2] Here's a better link: http://www.scit.wlv.ac.uk/~jphb/spos...alls/stat.html [/edit]

    [edit=3] I wrote a (convulted) program a long time ago that does this, you can see it if you like: http://dwks.theprogrammingsite.com/myprogs/df.htm [/edit] [edit=4] Never mind, it doesn't use stat. Okay, I'll stop editing now. [/edit]
    Last edited by dwks; 09-04-2006 at 02:08 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Try putting in a * for the folder/file name. If there's a function to find names by giving a name
    Last edited by twomers; 09-04-2006 at 02:09 PM.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Quote Originally Posted by dwks
    Sorry, I misread your question. (Or maybe it was edited.)
    It was edited to add "and cycle through them"
    EDIT:and is there any other simpler way in C++ to find directory contents?

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Well then I guess I just misread it.

    Quote Originally Posted by twomers
    Try putting in a * for the folder/file name.
    Uh . . . twomers, that's not going to help.

    [edit] You edited it. Oh well. Look what I did. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Why not? I remember using a file/folder thing from andrewxw's site and I threw in a * and it listed everything in the directory

    Something from here http://www.adrianxw.dk/SoftwareSite/index.html
    Last edited by twomers; 09-04-2006 at 02:12 PM.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    EDIT:and is there any other simpler way in C++ to find directory contents?
    Not really.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    argh this is my code
    Code:
    Look in new post
    How hard do you think it is going to be to incorporate that in to my code?
    Last edited by bikr692002; 09-04-2006 at 02:27 PM.

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Oh, you're using the Win32 version. Okay. Then you'd want the win32 stat, whatever that is. I don't know what it's called.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If you look carefully, the FAQ detects subdirectories.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    I believe boost::filesystem can handle this.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  15. #15
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    >> I believe boost::filesystem can handle this.
    I think you know it can! I have to investigate this boost jazz.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading File Names
    By Thrack in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2007, 05:08 PM
  2. Setting DACL for Files and Folders
    By IfYouSaySo in forum Windows Programming
    Replies: 6
    Last Post: 01-07-2006, 01:27 AM
  3. Files not updating in folder
    By BobS0327 in forum Tech Board
    Replies: 4
    Last Post: 06-06-2005, 05:55 PM
  4. Accessing a Specific Text Line Inside CEditView :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2002, 08:12 PM