-
Notifications
You must be signed in to change notification settings - Fork 3
/
MOVE.PAS
125 lines (116 loc) · 2.93 KB
/
MOVE.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2022
@website(https://www.gladir.com/msdos0)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program Move;
Uses DOS;
Var
Language:(_French,_English,_Germany,_Italian,_Spain);
TmpLanguage:String;
Function StrToUpper(S:String):String;
Var
I:Byte; { Compteur de boucle attribue a la chaine de caracteres }
Begin
For I:=1to Length(S)do S[I]:=UpCase(S[I]);
StrToUpper:=S;
End;
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
Language:=_French;
TmpLanguage:=GetEnv('LANGUAGE');
If TmpLanguage<>''Then Begin
If TmpLanguage[1]='"'Then TmpLanguage:=Copy(TmpLanguage,2,255);
If StrToUpper(Copy(TmpLanguage,1,2))='EN'Then Language:=_English Else
If StrToUpper(Copy(TmpLanguage,1,2))='GR'Then Language:=_Germany Else
If StrToUpper(Copy(TmpLanguage,1,2))='IT'Then Language:=_Italian Else
If StrToUpper(Copy(TmpLanguage,1,2))='SP'Then Language:=_Spain;
End;
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')Then Begin
Case Language of
_Germany:Begin
WriteLn('Verschiebt Dateien und benennt Dateien und Verzeichnisse um.');
WriteLn;
WriteLn('MOVE [Laufwerk:][Pfad]Dateiname[,...] Ziel');
End;
_English:Begin
WriteLn('Moves files and renames files and directories.');
WriteLn;
WriteLn('MOVE [drive:][path]filename1[,...] destination');
End;
Else Begin
WriteLn('MOVE : Cette commande permet de deplacer un fichier.');
WriteLn;
WriteLn('Syntaxe : MOVE source destination');
End;
End;
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.