Thread: looping through all files in a directory

  1. #1
    Registered User
    Join Date
    May 2009

    looping through all files in a directory


    I'm trying to loop through a bunch of images for processing in a C program. I'm having trouble finding a tutorial or anything on how to do it. I'm essentially looking for some kind of for/while loop that can open the file, pull some info out of it, close it and then move on to the next one until it has gone through every file in the folder.

    It would also be amazing if someone could point me in the direction of a way to determine how many files are in the directory without having to loop through each one and count (if that's even possible).

    Thanks very much!!


  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    readdir() or scandir()

    You do not have to open files to count them.

    qv. Simple Directory Lister Mark II - The GNU C Library

    This for GNU, I don't know about MS...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Examples of how to find files in a directory is given in the FAQ.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

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. All files in a directory
    By cloudy in forum Linux Programming
    Replies: 1
    Last Post: 06-09-2008, 01:50 AM
  3. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  4. Moving files from one directory to multiple dirs
    By csj561 in forum C Programming
    Replies: 7
    Last Post: 03-18-2005, 03:52 PM
  5. Reading files in a directory
    By roktsyntst in forum Windows Programming
    Replies: 5
    Last Post: 02-07-2003, 10:04 AM