1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
bool ZipFolder(char* file,char* Archieve,bool Recursive=false){ //it is Recursive
if (!comp.isOpen())
comp.open(Archieve );
char Temp[MAX_PATH];
WIN32_FIND_DATAA data;
StringCchCopyA(Temp,MAX_PATH,file);
StringCchCatA(Temp,260,"\\*");
HANDLE hFind = FindFirstFileA(Temp,&data);
if (hFind == INVALID_HANDLE_VALUE) return false;
StringCchCopyA(Temp,MAX_PATH,file);
StringCchCatA(Temp,260,"\\");
StringCchCatA(Temp,260,data.cFileName);
if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && strcmp(data.cFileName,".") && strcmp(data.cFileName,".."))
ZipFolder(Temp,Archieve,true);
ifstream fil( Temp, ios::in | ios::binary );
if (fil.is_open())
{
comp.addEntry(Temp);
comp << fil;
}
FindNextFileA(hFind,&data);
while (GetLastError() != ERROR_NO_MORE_FILES)
{
StringCchCopyA(Temp,MAX_PATH,file);
StringCchCatA(Temp,260,"\\");
StringCchCatA(Temp,260,data.cFileName);
if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && strcmp(data.cFileName,".") && strcmp(data.cFileName,".."))
{
ZipFolder(Temp,Archieve,true);
FindNextFileA(hFind,&data); // **** It Fails here can you help??
continue;
}
ifstream fil( Temp, ios::in | ios::binary );
if (fil.is_open())
{
comp.addEntry(Temp);
comp << fil;
}
FindNextFileA(hFind,&data);
}
fil.close();
if (Recursive == false )
comp.close();
return true;
}
|