gpt4 book ai didi

c - FindFirstFile 未按预期工作

转载 作者:行者123 更新时间:2023-11-30 14:29:19 25 4
gpt4 key购买 nike

FindFirstFile win32 函数失败。请解决问题。谢谢

#include<Windows.h>

#include<stdio.h>
#include<string.h>
#include<stdlib.h>


#define ValidDir(data) strcmp(data.cFileName,".")&&strcmp(data.cFileName,"..")

void MergeDir(char *path)
{

WIN32_FIND_DATA data={0};
HANDLE h;
int nFiles,i=0;
char temp[MAX_PATH];
char **files = malloc(sizeof(char*)*10000);
sprintf(temp,"%s*.*",path);//path = c:\windows name = *.*
h = FindFirstFile(temp,&data);//temp = c:\windows\*.*
/Invalid handle is being returned.....
if(h != INVALID_HANDLE_VALUE){ //Check whether we got valid handle or not
i = 0;
do{
if(ValidDir(data)){//Checks whether the Dir is . or ..
files[i] = malloc(sizeof(char)*MAX_PATH);
sprintf(files[i++],"%s%s",path,data.cFileName);
}
}while(FindNextFile(h,&data));
nFiles = --i;
FindClose(h);

for(i = 0; nFiles > 0 && i < nFiles-1; i++){
printf("\n%s\n%s\n----------------",files[i],files[i+1]);
}
}

}
int main()
{
//list all files in the following directory
MergeDir("D:\\IIIT\\Sem2\\IRE\\Processed\\");
return 0;
}

最佳答案

问题已解决,我的项​​目设置为 UNICODE,并且我传递了一个 asci 字符串,因此 FindFirstFile 失败。感谢您的建议

关于c - FindFirstFile 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4821097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com