Thread: FindNextFile always fails - FindFirstFile OK

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    44

    FindNextFile always fails - FindFirstFile OK

    I've managed to get rename file/directory to work and some other API stuff I've used (console program so far), but FindNextFile is mystifying. I've read every example of code I can find and it's simple. Note: I do not wish to copy other peoples programs or sections verbatim but program it as I would do. I have a suspicion it might have something to do with TCHAR as most datatypes mystify me still (assemble programmer at heart).

    ***********************************
    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <string.h>
    #include <tchar.h>
    
    int main(int argc, char *argv[])
    {
    
    WIN32_FIND_DATA myfind;
    HANDLE hfd;
    int x;
    DWORD dx = 200;
    TCHAR currdir[300];
    char szer = {0};
    char nl = {10};
    char bslsh[2] = {92, 0};
    
    x = GetCurrentDirectory(dx, currdir);
    printf("currdir at run time %s %c", currdir, nl);
    
    currdir[0] = szer;
    currdir[1] = szer;
    lstrcat (currdir, "C:");
    lstrcat (currdir, bslsh);
    lstrcat (currdir, "Documents And Settings");
    lstrcat (currdir, bslsh);
    lstrcat (currdir, "jlewandowsk2");
    lstrcat (currdir, bslsh);
    lstrcat (currdir, "*");
    printf("DIR built %s %c", currdir, nl);
    x = SetCurrentDirectory(currdir);
    
    x = GetCurrentDirectory(dx, currdir);
    printf("SET DIR %s %c", currdir, nl);
    printf("%c", nl);
    
    myfind.cFileName[0] = szer;
    hfd = FindFirstFile(currdir, &myfind);
    printf("handle %d ", hfd);
    printf("FIRST file-dir %s %c", myfind.cFileName, nl);
    
    while ( FindNextFile (hfd, &myfind) ) {
      printf("while loop %c", nl);
      printf("NEXT file-dir %s %c", myfind.cFileName, nl);
    }
    FindClose(hfd);
    
    getchar();
    return 0;
    }
    Last edited by jlewand; 02-02-2012 at 01:32 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. FindNextFile
    By Ducky in forum Windows Programming
    Replies: 17
    Last Post: 08-30-2009, 02:53 AM
  2. FindFirstFile and FindNextFile
    By scwizzo in forum Windows Programming
    Replies: 15
    Last Post: 03-12-2008, 04:50 PM
  3. Msdn example code (FindFirstFile, FindNextFile
    By Probose in forum Windows Programming
    Replies: 2
    Last Post: 09-22-2006, 04:16 PM
  4. FindFirstFile/FindNextFile
    By aff501 in forum C Programming
    Replies: 2
    Last Post: 07-13-2006, 04:16 PM
  5. FindNextFile()
    By siavoshkc in forum C++ Programming
    Replies: 9
    Last Post: 03-03-2006, 09:47 AM