如何把多個檔案合併為一個檔案,之後又可以解開? |
答題得分者是:anqiYao
|
jeffreck
高階會員 發表:247 回覆:340 積分:197 註冊:2003-01-23 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
參考: http://www.1delphistreet.com/vb/scripts/ShowCodeAsText.asp?txtCodeId=311&lngWId=7
!**************************************
! for :File Splitter / Joiner
!**************************************
Zip
!**************************************
! Name: File Splitter / Joiner
! Description:The Functions Can Split A File Into Many Pieces And Then Rejoin At A Later Date.
! By: wrastus
!
!
! Inputs:Two Sample Calls:
SplitFile('C:\afilename.exe',40000);
UnSplit('C:\samefilenameasabovewith-rtr-extension.rtr',40000);
!
! Returns:None
!
!Assumes:None
!
!Side Effects:None
!This code is copyrighted and has limited warranties.
!Please see http://www.1DelphiStreet.com/xq/ASP/txtCodeId.311/lngWId.7/qx/vb/scripts/ShowCode.htm
!for details.
!**************************************
function Smaller(const a,b:LongInt) :LongInt; begin if(a < b)then begin Result := a; end else if(b > 0)then begin Result := b end else Result := 0; end; Function SplitFile(FFileName : AnsiString; SplitSize : Longint): Boolean; Var InFile : TFileStream; OutFile : TFileStream; FilePlace : Integer; INI : TIniFile; FileInfo : TFinfo; Begin InFile := TFileStream.Create(FFileName,fmOpenRead); If InFile.Size > SplitSize Then Begin FilePlace := 0; While InFile.Position < InFile.Size Do Begin Inc(FilePlace); OutFile := TFileStream.Create(FFileName '.' FormatFloat('000',FilePlace), fmCreate); OutFile.CopyFrom(InFile,Smaller(SplitSize,InFile.Size - InFile.Position)); OutFile.Free; End; End Else ShowMessage('The File Is To Small To Split'); InFile.Free; INI := TIniFile.Create(ChangeFileExt(FFileName,'.rtr')); INI.WriteString('Files','Number',IntToStr(FilePlace)); INI.WriteString('Files','Name',FFileName); INI.Free; Result := True; End; Function UnSplit(FFileName : TFileName; BufferSize : LongInt):Boolean; Var INI : TIniFile; InFile : TFileStream; OutFile : TFileStream; FilePlace : Integer; NFiles : Integer; FFile : TFileName; BytesRead : LongInt; Buffer : Pointer; FString : TFileName; Begin GetMem(Buffer,BufferSize); INI := TIniFile.Create(FFileName); NFiles := StrToInt(INI.ReadString('Files','Number','0')); FFile := INI.ReadString('Files','Name','0'); OutFile := TFileStream.Create(FFile,fmCreate); FilePlace := 1; While FilePlace <= NFiles Do Begin FString := (FFile '.' FormatFloat('000',FilePlace)); InFile := TFileStream.Create(FString,fmOpenRead); While InFile.Size <> InFile.Position Do Begin Inc(FilePlace); BytesRead := InFile.Read(Buffer^,BufferSize); OutFile.Write(Buffer^,BytesRead); End; InFile.Free; End; Result := True; OutFile.Free; End;Also Two Sample Calls: SplitFile('C:\afilename.exe', 40000); UnSplit('C:\samefilenameasabovewith-rtr-extension.rtr', 40000);--- 奉行寶蘭主義 服從天使領導 保衛各版安全 完成KTop大業 |
anqiYao
一般會員 發表:1 回覆:3 積分:5 註冊:2003-04-18 發送簡訊給我 |
procedure TForm1.LinkFiles(SourceFiles:TStrings;DestFile:string); var MS0,MS:TMemoryStream; W:TWriter; i:integer; begin MS0:=TMemoryStream.Create; try MS:=TMemoryStream.Create; W:=TWriter.Create( (MS0,$10000); try for i:=0 to SourceFiles.Count-1 do begin W.WriteString(ExtractFileName(SourceFiles[i])); //寫入文件名 MS.Clear; MS.LoadFromFile(SourceFiles[i]); //載入文件 W.WriteInteger(MS.Size); //寫入長度 W.Write(MS.Memory^,MS.Size); //寫入buffer end; finally W.Free; MS.Free; end; MS0.Position:=0; MS0.SaveToFile(DestFile); finally MS0.Free; end; end; procedure TForm1.UnLinkFile(SourceFile: string;DestDir:string); var MS0,MS:TMemoryStream; R:TReader; FileName:string; begin MS0:=TMemoryStream.Create; try MS0.LoadFromFile(SourceFile); //載入合並文件 MS0.Position:=0; R:=TReader.Create(MS0,$10000); MS:=TMemoryStream.Create; try while MS0.Position |
XrayWang
一般會員 發表:3 回覆:5 積分:1 註冊:2003-12-11 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |