How to get names to all files/folders in a folder?

This is a discussion on How to get names to all files/folders in a folder? within the C Programming forums, part of the General Programming Boards category; Hi all! I am quite new to ANSI C so here comes a newbee question: How to get names to ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    9

    How to get names to all files/folders in a folder?

    Hi all!
    I am quite new to ANSI C so here comes a newbee question:
    How to get names to all files/folders in a folder without knowing their names?
    fopen() workes fine when you know the name of the file.
    As far as I have found out this isn't supported in the library but what is the way to solve it?

    Many thanks
    Marcux

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    I don't know of a standard way of doing that. These seems more like a script kind of thing. Why do you want to do this ?
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    40
    I think the library you need is dirent.h
    this will give you functions like opendir() and readdir()
    You might also need sys/stat.h for stat()

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    9
    I have got an application that in a specific situation produces files in a folder and will not stop untill hd is full ( a bugg ofcause) but til the owner of that software has fixed the bugg I want to write a small app that checkes the folder and if it is not empty delete all files. That is why I want to find a way to "browse" a folder and I can imagine that there are more situations that you are interested in finding out the contents of a folder.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,883
    What is your platform and compiler?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,656
    There's always the FAQ...

    But if all you're interested in is deleting all the files in a given folder, then a 1-line command file will do the trick.

    You can even schedule it to do it automatically.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading .dat files from a folder in current directory...
    By porsche911nfs in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2009, 09:52 PM
  2. reading folder names..how is it done ?
    By roalme00 in forum C++ Programming
    Replies: 8
    Last Post: 01-11-2008, 09:34 AM
  3. Hiding a folder
    By nextstep in forum Windows Programming
    Replies: 16
    Last Post: 03-20-2005, 02:07 PM
  4. how to get names of files in folder
    By kiku in forum C++ Programming
    Replies: 3
    Last Post: 03-07-2005, 05:51 PM
  5. is there a way to write the file names in a folder in a text file?
    By Commander in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 08-15-2002, 05:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21