[C/C++ 演算法]純C++讀取清單列表進行檔案打包和解打包
[C/C++ 演算法]純C++讀取清單列表進行檔案打包和解打包
C++二進位檔案讀寫、GetFileSize、C++偵測檔案大小、C++檔案路徑分割、C++抓取檔名、C++抓取副檔名、C++建立目錄、C++判斷目錄是否存在、C++記憶體清空、C++ vector使用、C++文字檔讀取、C++動態配置記憶體、GetFileName
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <vector> #include <direct.h> using namespace std; //最多打包文件個數 #define MAX_FILE_COUNT 1024 //最大路徑字元長度 #define MAX_PATH 260 //文件頭 struct FileHead { }; char char gchrFileExt[20]; void GetFileName(char *data); long GetFileSize(FILE *pf); int main(int argc, char *argv[]) { buf[strlen(buf)-1]=’\0′; vec_file.push_back(buf); strbuf=vec_file[i]; strcpy(buf, strbuf.c_str()); pWorkFile= fh.FileLen[i] = fclose(pWorkFile); pWorkFile = ‘\0’; fh.FileCount++; pWorkFile=’\0′; pWorkFile = if ( NULL == pWorkFile ) { fclose(pWorkFile); fclose(pOutFile); return -1; } pTmpData = new unsigned if ( ferror(pWorkFile) ) { fclose(pWorkFile); fclose(pOutFile); return -2; } if ( ferror(pOutFile) ) { fclose(pWorkFile); fclose(pOutFile); return -3; } delete [] pTmpData; pTmpData=’\0′; fclose(pWorkFile); pCAB = memset(&fh,0x0,sizeof(fh)); fread(&fh,sizeof(fh),1,pCAB);//讀取文件檔頭 for ( int i = 0 ; i < fh.FileCount { pTmpData = new unsigned fread(pTmpData,fh.FileLen[i],1,pCAB); GetFileName(fh.FileName[i]); pWorkFile = ‘\0’; pWorkFile = fclose(pWorkFile); delete [] pTmpData; pTmpData=’\0′; } fclose(pCAB); } //獲取檔大小(傳入以二進制方式打開的檔指針) long GetFileSize(FILE *pf) { } void GetFileName(char *data) { { d=data[i]; gchrPath[j]=d; j++; } else { break; } if(i<(j-4)) { gchrFileName[i]=gchrPath[j-i-1]; gchrFileName[i+1]=’\0′; } else { gchrFileExt[k]=gchrPath[j-i-1]; k++; gchrFileExt[k]=’\0′; } gchrPath[i]=data[i]; } |