Thread: Run through a set of files

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    270

    Question Run through a set of files

    Say I have three directories A, B, C
    Now in each of those directories I have numerous file that have the following naming standard: file#.txt, where # is a number starting from 0 and going to 20

    How could I first go into directory A and run through all the files processing each one 1 at a time, then move to next directory etc and repeat?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    what about doing this:
    Code:
    #include <stdio.h>
    
    int main() {
      FILE *file; 
    
      file = fopen("data/hello#.txt", "r"); 
    
        fclose(file);
        return 0;
      }
    }
    And substituiting # with a variable and loop it, is that possible?

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    >> is that possible?
    Yes it is. Just make sure to fclose() every time you call fopen() in the loop.
    bit∙hub [bit-huhb] n. A source and destination for information.

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    sprintf should help
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 03:01 PM
  2. "if you love someone" :D
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-02-2003, 01:10 AM
  3. Set Classes
    By Nicknameguy in forum C++ Programming
    Replies: 13
    Last Post: 10-31-2002, 02:56 PM
  4. Set Classes
    By Nicknameguy in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2002, 07:40 PM