Win32递归读取文件时,能运行为什么读不出东西呀?//解决办法
Win32递归读取文件时,能运行为什么读不出东西呀?//
------解决方案--------------------
不要用'/'(linux)用'\'(windows)
strcat(path,"/*.*");
strcat(path,"\\*.*");
- C/C++ code
#include "stdafx.h" #include "Windows.h" #include "stdio.h" void Find(LPSTR path){ WIN32_FIND_DATA fs={0}; CHAR buf[512]={0}; strcpy(buf,path); strcat(path,"/*.*"); HANDLE hFind=FindFirstFile(path,&fs); BOOL goFind=TRUE; while(goFind){ if(fs.dwFileAttributes==FILE_ATTRIBUTE_ARCHIVE) { printf("%s\n",fs.cFileName); Sleep(1000); }else{ if(strcmp(fs.cFileName,".")&&strcmp(fs.cFileName,"..")){ CHAR buff[512]={0}; strcat(buff,buf); printf("[%s]\n",fs.cFileName); Sleep(1000); strcat(buff,"/"); strcat(buff,fs.cFileName); Find(buff); printf("-----------\n"); } } goFind=FindNextFile(hFind,&fs); } //free(nPath); FindClose(hFind); return; } int main(int argc, char* argv[]) { CHAR path[512]="E:/win32/dll_lib"; Find(path); return 0; }
------解决方案--------------------
不要用'/'(linux)用'\'(windows)
strcat(path,"/*.*");
strcat(path,"\\*.*");