最近修改升级代码,有个升级子目录的情况没考虑到。找了个代码,记录一下。
void copydir(char* src,char* dst)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
char tmpsrc[256];
strcpy(tmpsrc,src);
strcat(tmpsrc,"//*.*");
hFind = FindFirstFile(tmpsrc, &FindFileData);
if(hFind == INVALID_HANDLE_VALUE)
return;
CreateDirectory(dst,0);
do
{
char newdst[256];
strcpy(newdst,dst);
if(newdst[strlen(newdst)]!='//')
strcat(newdst,"//");
strcat(newdst,FindFileData.cFileName);
char newsrc[256];
strcpy(newsrc,src);
if(newsrc[strlen(newsrc)]!='//')
strcat(newsrc,"//");
strcat(newsrc,FindFileData.cFileName);
if(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{
if(strcmp(FindFileData.cFileName,".")!=0&&strcmp(FindFileData.cFileName,"..")!=0)
{
copydir(newsrc,newdst);
}
}else
{
CopyFile(newsrc,newdst,false);
}
}while(FindNextFile(hFind,&FindFileData));
FindClose(hFind);
}
void copydir(char* src,char* dst)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
char tmpsrc[256];
strcpy(tmpsrc,src);
strcat(tmpsrc,"//*.*");
hFind = FindFirstFile(tmpsrc, &FindFileData);
if(hFind == INVALID_HANDLE_VALUE)
return;
CreateDirectory(dst,0);
do
{
char newdst[256];
strcpy(newdst,dst);
if(newdst[strlen(newdst)]!='//')
strcat(newdst,"//");
strcat(newdst,FindFileData.cFileName);
char newsrc[256];
strcpy(newsrc,src);
if(newsrc[strlen(newsrc)]!='//')
strcat(newsrc,"//");
strcat(newsrc,FindFileData.cFileName);
if(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{
if(strcmp(FindFileData.cFileName,".")!=0&&strcmp(FindFileData.cFileName,"..")!=0)
{
copydir(newsrc,newdst);
}
}else
{
CopyFile(newsrc,newdst,false);
}
}while(FindNextFile(hFind,&FindFileData));
FindClose(hFind);
}