process all files with certain extension

This is a discussion on process all files with certain extension within the C Programming forums, part of the General Programming Boards category; is there a more portable way to do this? PHP Code: DIR  * currentdir ; struct dirent  * entry ; currentdir  ...

  1. #1
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946

    process all files with certain extension

    is there a more portable way to do this?

    PHP Code:
    DIR *currentdir;
    struct dirent *entry;

    currentdir opendir (".");

    if (
    currentdir)
    {
      while ((
    entry readdir (currentdir)))
        if (
    strstr ((*entry).d_name".wav"))
          
    do_stuff ((*entry).d_name);
      
    closedir (currentdir);
    }

    else
      
    printf ("error opening current directory\n"); 
    hello, internet!

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    in the shortest of terms, no.

    ::edit:: files management/disk managment is OS specific, so complete protablilty in a single code version is not probable.

    question:

    why (*entry).d_name

    instead of entry->d_name

    they are equivalents, no?
    Last edited by no-one; 08-05-2002 at 12:00 AM.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User TravisS's Avatar
    Join Date
    Jun 2002
    Posts
    536
    Some people just REALLY like the dot operator

  4. #4
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by TravisS
    Some people just REALLY like the dot operator
    actually it's more that i really hate the -> operator

    i dunno, i find it easier to think thru the code with (*foo).bar and not foo->bar
    hello, internet!

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Think of it this way: The left side of the arrow is a pointer, and one of its members is being accessed. Thus, you're pointing at the member of a structure.

    ptr->member;

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Or even
    ptr[0].member

    > is there a more portable way to do this?
    Nope, that's about at portable as it gets
    opendir is part of POSIX

  7. #7
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    hmm i should have known that something like this wouldnt be ANSI, but if it will run on any POSIX than that's enough portability for me.
    hello, internet!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Check number of times a process is running
    By linuxwolf in forum Windows Programming
    Replies: 6
    Last Post: 10-17-2008, 12:08 PM
  2. Error opening files in a different dir
    By Ozzie in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2008, 07:55 AM
  3. Working with muliple source files
    By Swarvy in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2008, 09:36 AM
  4. Program Deployment and DLL/OCX Files?
    By dfghjk in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2008, 03:47 AM
  5. accessing all files in a folder.
    By pastitprogram in forum C++ Programming
    Replies: 15
    Last Post: 04-30-2008, 11:56 AM

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