| Autor |
Beitrag |
Christian V.
      
Beiträge: 311
Win Xp Prof
Turbo Delphi 2005
|
Verfasst: Sa 05.03.05 17:13
Hallo, habe mich schon mit der Forumssuche beschäftigt:
www.delphi-forum.de/...t=ordner+ausw%E4hlen
Ich wollte fragen, ob ich auch angeben kann, wo die gesplitteten Dateien abgelegt werden sollen.
Weiss jemand wie das geht?
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:
| function SplitFile(FileName : TFileName; SizeofFiles : Integer) : integer; var i : Word; fs, sStream: TFileStream; SplitFileName: String; begin
fs := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try for i := 1 to Trunc(fs.Size / SizeofFiles) + 1 do begin SplitFileName := ChangeFileExt(FileName, '.'+ FormatFloat('000', i)); sStream := TFileStream.Create(SplitFileName, fmCreate or fmShareExclusive); try if fs.Size - fs.Position < SizeofFiles then SizeofFiles := fs.Size - fs.Position; sStream.CopyFrom(fs, SizeofFiles); finally sStream.Free; end; Result := i; end; finally fs.Free; end;
end;
function CombineFiles(FileName, CombinedFileName : TFileName) : Boolean; var i: integer; fs, sStream: TFileStream; filenameOrg: String; begin i := 1; fs := TFileStream.Create(CombinedFileName, fmCreate or fmShareExclusive); try while FileExists(FileName) do begin sStream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try fs.CopyFrom(sStream, 0); finally sStream.Free; end; Inc(i); FileName := ChangeFileExt(FileName, '.'+ FormatFloat('000', i)); end; finally fs.Free; end; end; |
_________________ Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
|
|
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Sa 05.03.05 17:20
|
|
Christian V. 
      
Beiträge: 311
Win Xp Prof
Turbo Delphi 2005
|
Verfasst: So 06.03.05 10:48
Danke
_________________ Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
|
|
Harry M.
      
Beiträge: 754
Win 2000, XP
D2005
|
Verfasst: Fr 09.09.05 14:03
Ich habe mal schnell aus Deinem Code nen kleines Prog gemacht (brauchte ich mal kurz  ) Das Zusammensetzten habe ich so wie Luckies Splitter gemacht.
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: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90:
| program Splitter;
{$APPTYPE CONSOLE}
uses SysUtils, Classes;
const AppName = 'Splitter';
var CopyStr: String = 'copy /b ';
function StringRemove(S: String): String; var TempStr : String; begin TempStr := S; Delete(TempStr, length(TempStr)-1, 1); RESULT := TempStr; end; procedure BuildBatchFile(Filename, LogStr: String); var Datei : System.Text; begin AssignFile(Datei, Filename); ReWrite(Datei); Writeln(Datei, LogStr); Closefile(Datei); end; function SplitFile(FileName : TFileName; SizeofFiles : Integer) : integer; var i : Word; fs, sStream: TFileStream; SplitFileName: String; begin fs := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try for i := 1 to Trunc(fs.Size / SizeofFiles) + 1 do begin SplitFileName := ChangeFileExt(FileName, '.'+ FormatFloat('000', i)); CopyStr := CopyStr+'"'+SplitFileName+'" + '; sStream := TFileStream.Create(SplitFileName, fmCreate or fmShareExclusive); try if fs.Size - fs.Position < SizeofFiles then SizeofFiles := fs.Size - fs.Position; sStream.CopyFrom(fs, SizeofFiles); finally sStream.Free; end; Result := i; end; finally fs.Free; end;
BuildBatchFile('Fusion.bat', StringRemove(CopyStr)+'"'+ParamStr(1)+'"'); end; function CheckArg: boolean; begin RESULT := FALSE; if FileExists(ParamStr(1)) then begin try StrToInt(ParamStr(2)); RESULT := TRUE; except writeln('Wrong split size'); end; end else writeln('File not found '+ParamStr(1)); end; begin if not CheckArg then begin writeln(''); writeln(''); writeln(''); writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'); writeln(AppName); writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'); writeln(''); writeln('Program usage:'); writeln(''); writeln(AppName+' File.dat 1024 : The file splits to 1024 bytes'); end else writeln('Done: '+IntToStr(SplitFile(ParamStr(1), StrToInt(ParamStr(2))))+' files'); end. |
Is sicher noch verbessungswürdig - aber meine Zwecke hats erfüllt 
_________________ Gruß Harry
Et spes me per dies sine te ducat et amor me ferat, si dolor spem tollit.
|
|
|