CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2002
    Posts
    71

    FindFirstFile() question

    Hi, I've been trying to use the FindFirstFile function for reading files from a given input directory. basically, at the command line I write:

    ProcessTextFiles "c:\data\*.txt"

    so that I pass in the directory string as shown above. Now, when I run the code snippet below, it seems to correctly go the directory I want and step through the .txt files one at a time but in the returned structure

    WIN32_FIND_DATA fileData;

    I can see that you can retrieve the current filename (i.e., with cFileName method) but only without the path. How can I used FindFirstFile in a way where I can get the entire path:

    for example:
    "cata\gg1.txt"
    vs just
    "gg1.txt"
    ??

    Thanks!



    if ((hFileRead = FindFirstFile(argv[1], &fileData)) != INVALID_HANDLE_VALUE){
    do{
    string FilenameWithFullPath = fileData.cFileName;
    //Process this next text file
    BuildDictionary.ProcessTextFile(FilenameWithFullPath);
    }while (FindNextFile(hFileRead, &fileData));
    }

  2. #2
    Join Date
    Aug 2002
    Location
    Redmond, WA, USA
    Posts
    88
    The truth is you cannot. You are responsible for appending on a path to the file. That is the way the API was designed.

    Besides, you know what the path is. You passed it in yourself. Just parse the string if you need it and append it to each filename you need.

    - Robert

  3. #3
    Join Date
    Sep 2002
    Posts
    71
    OK thanks. I was going to do that but thought that I must have missed something in the API and didn't want to reinvent the wheel.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured