Как разделить файл на куски по 1.44Mb, если его
размер больше чем дискета
CONST
MaxSize : Longint = 1440000; //байт
function ExtractFileNames(FileNames:string):string;
var
S:string;
begin
S:='';
while Pos('.', FileNames) > 0 do
begin
S:=S+Copy(FileNames,1,Pos('.',FileNames)-1);
Delete(FileNames,1,Pos('.',FileNames));
end;
result:=S;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
InFile,OutFile: FILE;
CopyBuffer : POINTER; { buffer for copying }
iRecsOK, iRecsWr, index: Integer;
sFileName,sFileExt,sFileFullName:string;
fFileSize: file of Byte;
Size:LongInt;
begin
sFileFullName:='C:\1\1.mp3';
sFileName:=ExtractFileName(sFileFullName);
sFileExt:=ExtractFileExt(sFileName);
sFileName:=ExtractFileNames(sFileName);
ShowMessage(sFileFullName+#13+sFilename+#13+sFileExt);
if FileExists(sFileFullName) then
begin
AssignFile(fFileSize, sFileFullName);
FileMode := 0; {Set file access to read only }
Reset(fFileSize);
Size := FileSize(fFileSize); {Get File Size}
CloseFile(fFileSize);
ShowMessage(IntToStr(Size));
if Size>MaxSize then
begin {Divide}
Getmem(CopyBuffer, MaxSize); { allocate the buffer }
Assignfile(inFile,sFileFullName );//+ '.ZIP');
Reset(inFile,1);
index := 1;
repeat
AssignFile(outFile,sFileName +
'-'+IntToStr(index) + sFileExt);
Rewrite(OutFile,1);
inc(index);
BlockRead(InFile, CopyBuffer^, MaxSize,
iRecsOK);
BlockWrite(OutFile, CopyBuffer^, iRecsOK,
iRecsWr);
CloseFile(OutFile);
until (iRecsOK < MaxSize);
CloseFile(InFile);
FreeMem(CopyBuffer, MaxSize); { free the buffer }
ShowMessage('Done..!');
end
else
begin
ShowMessage('Do nothing..!');
end;
end
else
ShowMessage('File: '+sFileFullName+' not found');
end;
************************
Чтобы склеить файлы обратно в один, можно
воспользоваться DOS функцией copy;
copy /b file-1.xxx+file-2.xxx+file-3.xxx file.mp3
|