-
Notifications
You must be signed in to change notification settings - Fork 0
/
MV.PAS
90 lines (83 loc) · 1.86 KB
/
MV.PAS
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
{ @author: Sylvain Maltais ([email protected])
@created: 2022
@website(https://www.gladir.com/xenix-0)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program Mv;
Uses DOS;
Function SplitFileName(s:String):String;
Var
D:DirStr;
N:NameStr;
E:ExtStr;
Begin
FSplit(S,D,N,E);
Splitfilename:=N+E;
End;
Function CopyFile(Source,Target:String):Boolean;
Var
SourceFile,TargetFile:File;
RecordsRead:Integer;
Buffer:Array[1..1000]of Byte;
Begin
CopyFile:=False;
Assign(SourceFile,Source);
{$I-}Reset(SourceFile,1);{$I+}
If IOResult<>0Then Begin
WriteLn('Fichier source introuvable ',Source);
Exit;
End;
Assign(TargetFile,Target);
{$I-}Rewrite(TargetFile,1);
BlockRead(SourceFile,Buffer,SizeOf(Buffer),RecordsRead);
While RecordsRead>0 do Begin
BlockWrite(TargetFile,Buffer,RecordsRead);
BlockRead(SourceFile,Buffer,SizeOf(Buffer),RecordsRead);
End;
Close(SourceFile);
Close(TargetFile);
{$I+}
CopyFile:=True;
End;
Function MoveFile(Source,Target:String):Boolean;
Var
F:File;
Begin
If(Source='')or(Target='')Then Begin
MoveFile:=False;
Exit;
End;
Source:=FExpand(Source);
Target:=FExpand(Target);
If(Source[1]<>Target[1])and(Source[2]=':')Then Begin { Unite de disque different ?}
{ Copie le fichier }
MoveFile:=CopyFile(Source,Target);
{ Supprime le fichier }
{$I-}Assign(F,Source);
Erase(F);
{$I+}
End
Else
Begin
{$I-}
Assign(F,Source);
Rename(F,Target+'\'+SplitFileName(Source));
MoveFile:=IOResult=0;
{$I+}
End;
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')Then Begin
WriteLn('MV : Cette commande permet de deplacer un fichier.');
WriteLn;
WriteLn('Syntaxe : MV source destination');
End
Else
If ParamCount=2Then Begin
If Not MoveFile(ParamStr(1),ParamStr(2))Then Begin
WriteLn('Erreur de d‚placement du fichier.');
End;
End
Else
WriteLn('Nombre de parametre invalide');
END.