Thread: Reading in filenames

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    Reading in filenames

    hey, i was just wondering how i would go about reading in the files in a certain directory (the same dir that the prog is running in) of a certain type. while ripping my (legal) cd's to my computer, the program i use (CDex) adds like: 01-bandname _ songname.mp3
    i think. but yea.. windows xp, dev-c++ 4.9.2. thanks
    Last edited by willc0de4food; 08-22-2005 at 03:00 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    hmm...i wrote a program which suites my needs. you can find the source here: http://www.angelfire.com/droid/willc...ource/rename.c

    but it would be really nice to know how to make a list of the filenames in a dir in C rather than using the system() & DOS commands, lol
    Last edited by willc0de4food; 08-22-2005 at 04:32 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > but it would be really nice to know how to make a list of the filenames in a dir in C
    http://faq.cprogramming.com/cgi-bin/...&id=1044780608
    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.

  4. #4
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    thanks
    mm..on the first example, which is claimed to be provided by you, i get errors on my compiler :-[
    Compiler: Default compiler
    Executing gcc.exe...
    gcc.exe "C:\Dev-Cpp\projects\finder.c" -o "C:\Dev-Cpp\projects\finder.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
    C:\Dev-Cpp\projects\finder.c: In function `walker':
    C:\Dev-Cpp\projects\finder.c:10: error: storage size of 'finder' isn't known
    C:\Dev-Cpp\projects\finder.c:15: error: `FA_DIREC' undeclared (first use in this function)
    C:\Dev-Cpp\projects\finder.c:15: error: (Each undeclared identifier is reported only once
    C:\Dev-Cpp\projects\finder.c:15: error: for each function it appears in.)
    C:\Dev-Cpp\projects\finder.c:15: error: `FA_ARCH' undeclared (first use in this function)

    C:\Dev-Cpp\projects\finder.c:26: error: `MAXPATH' undeclared (first use in this function)

    Execution terminated
    any ideas why? mm..the next example works, but i'll have to see if i can modify it for my needs.

    thanks
    Registered Linux User #380033. Be counted: http://counter.li.org

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Well, it can't find the structure
    Code:
    struct ffblk  finder;
    and some other things. Try this (it works in Dev-C++)
    Code:
    #include <unistd.h>
    
    void list(void) {
        DIR *dir;
        struct dirent *d;
    
        dir = opendir(".");  /* path to open */
    
        while(d = readdir(dir)) {
            puts(d->d_name);
        }
    
        closedir(dir);
    }
    All from memory. You should check the return value of opendir(), too.

    [edit]
    Or try the *NIX example in the FAQ. It's better than mine.
    [/edit]
    Last edited by dwks; 08-22-2005 at 01:35 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.

  6. #6
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    lol i am using the *nix example from the faq.
    Registered Linux User #380033. Be counted: http://counter.li.org

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    So does it work?
    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
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    yes, it makes a list of the filenames in the dir. but i can't filter out just the filenames w/the .mp3 extension. idk why, but its not working lol
    Registered Linux User #380033. Be counted: http://counter.li.org

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    h = FindFirstFile("*.*", &info);
    becomes
    h = FindFirstFile("*.mp3", &info);
    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.

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by willc0de4food
    yes, it makes a list of the filenames in the dir. but i can't filter out just the filenames w/the .mp3 extension. idk why, but its not working lol
    I suspect you're going to starve.
    Quote Originally Posted by Salem
    h = FindFirstFile("*.*", &info);
    becomes
    h = FindFirstFile("*.mp3", &info);
    Apparently, you can give a man some source code, but you can't make'm think.


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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Reading filenames and creating folders
    By Bitphire in forum C++ Programming
    Replies: 2
    Last Post: 03-03-2005, 01:38 PM
  3. Help Reading Data from Specific Filenames
    By RguyK128 in forum C Programming
    Replies: 4
    Last Post: 02-18-2005, 06:26 AM
  4. Reading only filenames
    By claytonross in forum C++ Programming
    Replies: 7
    Last Post: 01-12-2005, 04:17 PM
  5. reading filenames
    By Paul in forum C++ Programming
    Replies: 1
    Last Post: 07-01-2003, 10:02 AM