-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBASENAME.PAS
51 lines (45 loc) · 1.25 KB
/
BASENAME.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
{ @author: Sylvain Maltais ([email protected])
@created: 2021
@website(https://www.gladir.com/corail)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program BaseName;
Function GetBaseName(PathSpec:String):String;
Var
HoldIndex,ScanIndex:Integer;
ThisChar:Char;
Begin
HoldIndex := 1;
For ScanIndex:=1 TO Length (PathSpec)do Begin
ThisChar:=PathSpec[ScanIndex];
If ThisChar in[':','/','\']Then HoldIndex:=ScanIndex+1
End;
GetBaseName:=Copy(PathSpec,HoldIndex,Length(PathSpec)-HoldIndex+1);
End;
Function RemoveSuffixe(PathSpec,Suffixe:String):String;Begin
If Copy(PathSpec,Length(PathSpec)-Length(Suffixe)+1,Length(Suffixe))=Suffixe Then Begin
RemoveSuffixe:=Copy(PathSpec,1,Length(PathSpec)-Length(Suffixe));
End
Else
RemoveSuffixe:=PathSpec;
End;
Var
Path:String;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('BASENAME : Cette commande permet de retourner le nom du fichier seulement.');
WriteLn;
WriteLn('Syntaxe : BASENAME path [suffixe]');
End
Else
If ParamCount>0Then Begin
Path:=GetBaseName(ParamStr(1));
If ParamCount=2 Then Path:=RemoveSuffixe(Path,ParamStr(2));
WriteLn(Path);
End
Else
Begin
WriteLn('Parametre requis !');
End;
END.