C++ 列出文件夹下的所有文件

来源:互联网 发布:淘宝服装代理 编辑:程序博客网 时间:2024/04/30 17:07

转自:http://hi.baidu.com/abenmao32032/item/935773889b17efc599255ffd

#include <iostream>
#include <string>
#include <windows.h>

using namespace std;
void find(char *IpPath)
{
    char szFind[100];
    char szFile[100];
    WIN32_FIND_DATA FindFileData;
    strcpy(szFind,IpPath);
    strcat(szFind,"*.*");
    HANDLE hFind=::FindFirstFile(szFind,&FindFileData);
    if (INVALID_HANDLE_VALUE == hFind)
        return;
    while(true)
    {
        if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            if(FindFileData.cFileName[0]!='.')
            {
                strcpy(szFile,IpPath);
                strcat(szFile,"");
                strcat(szFile,FindFileData.cFileName);
                strcat(szFile,"\\*.*");
                find(szFile);
            }
        }
        else
        {
            cout <<FindFileData.cFileName << endl ;
        }
        if(!FindNextFile(hFind,&FindFileData))
            break;
    }
    FindClose(hFind);
}
void main()
{
    char *p="F:";
    find(p);
}

0 0
原创粉丝点击