copyfile
#include <windows.h>#include <stdio.h>
int main()
{
WIN32_FIND_DATA szFindData;
HANDLE hFindHdl;
char szSrcPath[MAX_PATH];
char szDstPath[]="D:\\tmp\\";
char szPathTmp[MAX_PATH];
char szTmpDst[MAX_PATH];
BOOL finshed=false;
if(!CreateDirectory(szDstPath,NULL))
printf("create error\n");
GetCurrentDirectory(MAX_PATH,szPathTmp);
sprintf(szSrcPath,"%s%s",szPathTmp,"\\*.txt");
hFindHdl=FindFirstFile(szSrcPath,&szFindData);
lstrcpy(szTmpDst,szDstPath);
while(!finshed)
{
//源文件名
lstrcpy(szSrcPath,szPathTmp);
sprintf(szSrcPath,"%s","\\");
lstrcat(szSrcPath,szFindData.cFileName);
printf("src name :%s\n",szSrcPath);
//目的文件名
lstrcpy(szDstPath,szTmpDst);
lstrcat(szDstPath,szFindData.cFileName);
printf("dst name: %s\n",szDstPath);
if(!CopyFile(szSrcPath,szDstPath,FALSE))
printf("copy error :%d\n",GetLastError());
if(!FindNextFile(hFindHdl,&szFindData))
{
if(GetLastError()==ERROR_NO_MORE_FILES)
finshed=true;
else
printf("next error\n");
}
}
if(!CloseHandle(hFindHdl))
printf("close error");
return 0;
}
这是在学习VC的时候,想写一个文件拷贝的小程序,结果发现错误我想了好长时间没有看出什么问题。不知道是哪里的问题
,请高手看看!