Author: Güray CELIK
How can i divide a file into 1.44 mb volumes if file size is longer than floppy
capacity?
Answer:
1 const
2 MaxSize: Longint = 1440000; //byte
3
4 function ExtractFileNames(FileNames: string): string;
5 var
6 S: string;
7 begin
8 S := '';
9 while Pos('.', FileNames) > 0 do
10 begin
11 S := S + Copy(FileNames, 1, Pos('.', FileNames) - 1);
12 Delete(FileNames, 1, Pos('.', FileNames));
13 end;
14 result := S;
15 end;
16
17 procedure TForm1.SpeedButton1Click(Sender: TObject);
18 var
19 InFile, OutFile: file;
20 CopyBuffer: POINTER; { buffer for copying }
21 iRecsOK, iRecsWr, index: Integer;
22 sFileName, sFileExt, sFileFullName: string;
23 fFileSize: file of Byte;
24 Size: LongInt;
25 begin
26 sFileFullName := 'C:\1\1.mp3';
27 sFileName := ExtractFileName(sFileFullName);
28 sFileExt := ExtractFileExt(sFileName);
29 sFileName := ExtractFileNames(sFileName);
30
31 ShowMessage(sFileFullName + #13 + sFilename + #13 + sFileExt);
32
33 if FileExists(sFileFullName) then
34 begin
35 AssignFile(fFileSize, sFileFullName);
36 FileMode := 0; {Set file access to read only }
37 Reset(fFileSize);
38 Size := FileSize(fFileSize); {Get File Size}
39 CloseFile(fFileSize);
40 ShowMessage(IntToStr(Size));
41
42 if Size > MaxSize then
43 begin {Divide}
44 Getmem(CopyBuffer, MaxSize); { allocate the buffer }
45
46 Assignfile(inFile, sFileFullName); //+ '.ZIP');
47 Reset(inFile, 1);
48
49 index := 1;
50 repeat
51 AssignFile(outFile, sFileName + '-' + IntToStr(index) + sFileExt);
52 Rewrite(OutFile, 1);
53 inc(index);
54 BlockRead(InFile, CopyBuffer^, MaxSize, iRecsOK);
55 BlockWrite(OutFile, CopyBuffer^, iRecsOK, iRecsWr);
56 CloseFile(OutFile);
57 until (iRecsOK < MaxSize);
58 CloseFile(InFile);
59 FreeMem(CopyBuffer, MaxSize); { free the buffer }
60 ShowMessage('Done..!');
61
62 end
63 else
64 begin
65 ShowMessage('Do nothing..!');
66 end;
67 end
68 else
69 ShowMessage('File: ' + sFileFullName + ' not found');
70 end;
If you can put it back, you can use DOS copy function;
copy /b file-1.xxx+file-2.xxx+file-3.xxx file.mp3
|