home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
PAS_0593
/
COPYSHOW.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-05-09
|
2KB
|
81 lines
{─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 99 of 132
From : Rob Perelman 1:202/1308.0 02 May 93 13:47
To : All
Subj : Copyshow
────────────────────────────────────────────────────────────────────────────────
I got it to work. I sat down and looked at my code for Copyshow and did
a rewrite that works in 10 minutes. It works just like DOS's copy,
except it shows you progress in percentage. Check this out...if you
have any suggestions to tweak it, please tell me!}
Program CopyShow;
Uses Dos,Crt;
Var
Buf: Array[1..8092] of Byte;
FromF, ToF: File;
NumRead, NumWritten: Word;
Temp: PathStr;
PreDest: String;
Dir: DirStr;
Name: NameStr;
Ext: ExtStr;
DirInfo: SearchRec;
Total: LongInt;
Procedure Error(ErrorMsg: String);
Begin
Writeln(ErrorMsg);
Halt(1);
End;
Function ExistDir(DirName: String):Boolean;
Var Dir: String;
Exist: Boolean;
Begin
GetDir(0, Dir);
If DirName[Length(DirName)]='\' then Delete(DirName,Length(DirName),1);
{$I-} ChDir(DirName); {$I+}
Exist:=(IOResult=0) and (DirName<>'');
ChDir(Dir);
ExistDir:=Exist;
End;
Var
OldX,OldY : Word;
Begin
If ParamCount=0 then Error('Required parameter missing');
Temp:=ParamStr(1);
If ParamCount=1 then PreDest:='.\' Else PreDest:=ParamStr(2);
FSplit(PreDest, Dir, Name, Ext);
PreDest:=FExpand(Dir)+Name+Ext;
FSplit(Temp, Dir, Name, Ext);
Dir:=FExpand(Dir);
If PreDest=Dir then Error('File cannot be copied onto itself');
FindFirst(ParamStr(1), Archive, DirInfo);
If DosError<>0 then Error('File not found') Else While DosError=0 do Begin
If ExistDir(PreDest) then Temp:=PreDest+DirInfo.Name Else Temp:=PreDest;
Assign(FromF, Dir+DirInfo.Name);
Reset(FromF,1);
Assign(ToF, Temp);
Rewrite(ToF, 1);
Total:=0;
Write(DirInfo.Name:12,' ');
OldX := WhereX; OldY := WhereY;
Repeat
GotoXY(OldX,OldY);
Write('==>',Total/DirInfo.Size*100:5:2,'%':10);
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
BlockWrite(ToF, Buf, NumRead, NumWritten);
Inc(Total, NumWritten);
Until (NumRead=0) or (NumWritten<>NumRead);
GetFTime(FromF, Total);
SetFTime(ToF, Total);
Close(FromF);
Close(ToF);
Writeln;
FindNext(DirInfo);
End;
End.