您的位置:首页 > 其它

遍历文件和文件夹 获取文件名后缀

2016-01-08 09:46 453 查看
//遍历文件夹

int FindFile(char* lpPath)
{
char szFind[1000] = {0};
WIN32_FIND_DATA FindFileData;
strcpy(szFind,lpPath);
strcat(szFind,"\\*.*");
HANDLE hFind = ::FindFirstFile(szFind,&FindFileData);
if (INVALID_HANDLE_VALUE==hFind)
{
return -8;//没有文件
}
while(1)
{
if (FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{
if (FindFileData.cFileName[0]!='.')
{
char szfile[500] = {0};
strcpy(szfile,lpPath);
strcat(szfile,"\\");
strcat(szfile,FindFileData.cFileName);
FindFile(szfile);
}
}
else
{
//文件名+路径
char tmpupload[1000] = {0};
strcpy(tmpupload,lpPath);
strcat(tmpupload,"\\");
strcat(tmpupload,FindFileData.cFileName);

//下载

}
if (!FindNextFile(hFind,&FindFileData))
{
break;
}
}
FindClose(hFind);//用完记得关闭
return 0;

}
<pre name="code" class="cpp">int GetFileNameExtension(char*filename,char*Extension)//获取文件名后缀
{
CString tmp;
tmp = filename;
tmp.MakeLower();//转成小写
char fileTmp[1000] = {0};
if (tmp.GetLength()>1000)
{
return -27;
}
strcpy(fileTmp,tmp.GetBuffer());
char*tmpname = strrchr(fileTmp,'.');
if (tmpname==NULL)
{
return -1;//执行失败
}
if (strlen(tmpname)>10)
{
return -27;
}
strcpy(Extension,tmpname+1);
return 0;

}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: