File name reading question

This is a discussion on File name reading question within the C++ Programming forums, part of the General Programming Boards category; I want to be able to put all the file names of a specific extension into a string array so ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    411

    File name reading question

    I want to be able to put all the file names of a specific extension into a string array so i can load them into my program.

    How dose that work?

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    have to use a file search of some sort...then maybe build a data base...
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    15
    If you're doing this in WIN32API look up the functions FindFirstFile
    and FindNextFile in the Help or in a book.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    > I want to be able to put all the file names of a specific extension into a string array
    Well the way you find filenames is by using

    For DOS/Windows
    findfirst and findnext
    You'll need to look up the exact names, there are several variants, depending on which specific MS OS you have

    For Unix/Linux
    opendir, readdir, closedir are the functions you want
    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.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    I looked it up on MSDN, and im still not quite getting it.

    I tried something like this, but it just crashes the program when it runs.

    WIN32_FIND_DATA * data;
    FindFirstFile("*.txt",data);
    filename = data->cFileName;

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    if filename is a char* you will need to use strcpy() instead of = .
    secondly salem has posted an excellent directory walker at least twice.A search will throw that up.You will learn much from that small piece of code.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    > WIN32_FIND_DATA * data;
    > FindFirstFile("*.txt",data);
    That's because you should have written...

    WIN32_FIND_DATA data;
    FindFirstFile("*.txt", &data);

    When something takes a * parameter, it's not good enough to simply declare a variable of that type, you've got to make sure it points somewhere.
    Or, you declare a variable without the *, and you pass &var to the function instead.


    > secondly salem has posted an excellent directory walker at least twice.
    *blush*
    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. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Newbish Question file reading question....
    By kas2002 in forum C Programming
    Replies: 23
    Last Post: 05-17-2007, 01:06 PM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 04:39 AM
  4. question about reading in strings from a file :>
    By bball887 in forum C Programming
    Replies: 8
    Last Post: 04-13-2004, 07:24 PM

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