利用VC怎样去读取文件夹中的信息?例如:F:\download
比如说读取这个文件夹下有几个文件  
还有能不能得到文件目录信息:比如F:\download\ddd.txt
等等信息,越详细越好。
谢谢!

解决方案 »

  1.   

    #include <windows.h>
    #include <stdio.h>WIN32_FIND_DATA FileData; 
    HANDLE hSearch; 
    DWORD dwAttrs; 
    char szDirPath[] = "c:\\TEXTRO\\"; 
    char szNewPath[MAX_PATH]; 
    char szHome[MAX_PATH]; 
     
    BOOL fFinished = FALSE; 
     
    // Create a new directory. 
     
    if (!CreateDirectory(szDirPath, NULL)) 

        printf("Couldn't create new directory."); 
        return;

     
    // Start searching for *.* files in the current directory. 
     
    hSearch = FindFirstFile("*.*", &FileData); 
    if (hSearch == INVALID_HANDLE_VALUE) 

        printf("No files found."); 
        return;

     
    //FileData中有文件的详细信息 
    while (!fFinished) 

        printf(FileData.cFileName);
     
        if (!FindNextFile(hSearch, &FileData)) 
        {
            if (GetLastError() == ERROR_NO_MORE_FILES) 
            { 
                MessageBox(hwnd, "No more files.", 
                    "Search completed.", MB_OK); 
                fFinished = TRUE; 
            } 
            else 
            { 
                printf("Couldn't find next file."); 
                return;
            } 
        }

     
    // Close the search handle. 
     
    FindClose(hSearch);