-
Notifications
You must be signed in to change notification settings - Fork 3
/
ATTRIB.PAS
235 lines (224 loc) · 6.58 KB
/
ATTRIB.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2021
@website(https://www.gladir.com/msdos0)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program Attrib;
Uses DOS;
Var
Language:(_French,_English,_Germany,_Italian,_Spain);
IsAttrSetting:Array[Byte]of Boolean;
AttrAdd,AttrRemove:Word;
I:Byte;
SubDirectory:Boolean;
TmpLanguage:String;
Function StrToUpper(S:String):String;
Var
I:Byte;
Begin
For I:=1 to Length(S)do Begin
If S[I] in['a'..'z']Then S[I]:=Chr(Ord(S[I])-32);
End;
StrToUpper:=S;
End;
Function Path2Dir(Const Path:String):String;
Var
D:DirStr;
N:NameStr;
E:ExtStr;
Begin
Path2Dir:='';
If Path=''Then Exit;
FSplit(Path,D,N,E);
If E=''Then Begin
If D[Length(D)]<>'\'Then D:=D+'\';
D:=D+E;
End;
If D=''Then Path2Dir:='' Else
If D[Length(D)]<>'\'Then D:=D+'\';
Path2Dir:=D;
End;
Function SetPath4AddFile(Path:String):String;Begin
If Path=''Then GetDir(0,Path);
If Path[Length(Path)]<>'\'Then Path:=Path+'\';
SetPath4AddFile:=Path;
End;
Procedure SetAttribut(Var F:File);
Var
CurrAttr:Word;
Begin
GetFAttr(F,CurrAttr);
If AttrRemove and ReadOnly=ReadOnly Then CurrAttr:=CurrAttr and Not ReadOnly;
If AttrRemove and Archive=Archive Then CurrAttr:=CurrAttr and Not Archive;
If AttrRemove and Hidden=Hidden Then CurrAttr:=CurrAttr and Not Hidden;
If AttrRemove and SysFile=SysFile Then CurrAttr:=CurrAttr and Not SysFile;
If AttrAdd and ReadOnly=ReadOnly Then CurrAttr:=CurrAttr or ReadOnly;
If AttrAdd and Archive=Archive Then CurrAttr:=CurrAttr or Archive;
If AttrAdd and Hidden=Hidden Then CurrAttr:=CurrAttr or Hidden;
If AttrAdd and SysFile=SysFile THen CurrAttr:=CurrAttr or SysFile;
SetFAttr(F,CurrAttr);
End;
Procedure SetAttributFiles(FileSpec:String);
Var
Info:SearchRec;
CurrFile:File;
Found:Boolean;
Begin
FileSpec:=FExpand(FileSpec);
FindFirst(FileSpec,AnyFile,Info);
Found:=False;
While DOSError=0 do Begin
Found:=True;
If Info.Attr and Directory=Directory Then Begin
If(SubDirectory)Then Begin
If Not((Info.Name='.')or(Info.Name='..')or(Info.Name=''))Then Begin
SetAttributFiles(SetPath4AddFile(Path2Dir(FileSpec)+Info.Name)+'*.*');
End;
End;
End
Else
Begin
Assign(CurrFile,Path2Dir(FileSpec)+Info.Name);
SetAttribut(CurrFile);
End;
FindNext(Info);
End;
If Not Found Then WriteLn('Aucun resultat trouve');
End;
Procedure ShowAttribut;
Var
Info:SearchRec;
Begin
FindFirst('*.*',AnyFile and Not Directory,Info);
While DOSError=0 do Begin
If Info.Attr and ReadOnly=ReadOnly Then Write('r') Else Write('-');
If Info.Attr and SysFile=SysFile Then Write('s') Else Write('-');
If Info.Attr and Archive=Archive Then Write('a') Else Write('-');
If Info.Attr and Hidden=Hidden Then Write('h') Else Write('-');
If Info.Attr and VolumeID=VolumeID Then Write('v') Else Write('-');
If Info.Attr and Directory=Directory Then Write('d') Else Write('-');
Write(' ');
WriteLn(Info.Name);
FindNext(Info);
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)='/?'Then Begin
Case Language of
_English:Begin
WriteLn('ATTRIB - This command allow to request or change the attribute of a file.');
WriteLn;
WriteLn('Syntax: ATTRIB filename [+R|-R] [+A|-A] [+S|-S] [+H|-H]');
WriteLn;
WriteLn(' -A Clear archive attribut');
WriteLn(' +A Set archive attribut');
WriteLn(' -R Clear read only attribut');
WriteLn(' +R Set read only attribut');
WriteLn(' -S Clear system attribut');
WriteLn(' +S Set system attribut');
WriteLn;
WriteLn(' /S Recursive subdirectories');
End;
_Germany:Begin
WriteLn('ATTRIB - Zeigt Dateiattribute an oder „ndert sie.');
WriteLn;
WriteLn('ATTRIB [+R|-R] [+A|-A] [+S|-S] [+H|-H] [[Laufwerk:][Pfad]Dateiname] [/S]');
WriteLn;
WriteLn(' + Setzt ein Attribut.');
WriteLn(' - L”scht ein Attribut.');
WriteLn(' R Attribut fr ''Schreibgeschtzte Datei''');
WriteLn(' A Attribut fr ''Zu archivierende Datei''');
WriteLn(' S Attribut fr ''Systemdatei''');
WriteLn(' H Attribut fr ''Versteckte Datei''');
WriteLn;
WriteLn('/S Verarbeitet Dateien in allen Verzeichnissen des angegebenen Pfads.');
End;
Else Begin
WriteLn('ATTRIB - Cette commande permet de demander ou changer l''attribut d''un fichier.');
WriteLn;
WriteLn('Syntaxe : ATTRIB nomdufichier [+R|-R] [+A|-A] [+S|-S] [+H|-H] [/S]');
WriteLn;
WriteLn(' -A Enleve l''attribut d''archive');
WriteLn(' +A Ajout l''attribut d''archive');
WriteLn(' -H EnlŠve l''attribut cach‚');
WriteLn(' +H Ajout l''attribut cach‚');
WriteLn(' -R Enleve l''attribut de lecture seulement');
WriteLn(' +R Ajout l''attribut de lecture seulement');
WriteLn(' -S Enleve l''attribut de systŠme');
WriteLn(' +S Ajout l''attribut de systŠme');
WriteLn;
WriteLn(' /S Applique le changement dans les sous-r‚pertoires r‚cursivement.');
End;
End;
End
Else
If ParamCount=0Then ShowAttribut
Else
If ParamCount>0Then Begin
FillChar(IsAttrSetting,SizeOf(IsAttrSetting),0);
AttrAdd:=0;
AttrRemove:=0;
SubDirectory:=False;
For I:=1to ParamCount do Begin
If StrToUpper(ParamStr(I))='+R'Then Begin
AttrAdd:=ReadOnly;
IsAttrSetting[I]:=True;
End
Else
If StrToUpper(ParamStr(I))='-R'Then Begin
AttrRemove:=ReadOnly;
IsAttrSetting[I]:=True;
End
Else
If StrToUpper(ParamStr(I))='+H'Then Begin
AttrAdd:=Hidden;
IsAttrSetting[I]:=True;
End
Else
If StrToUpper(ParamStr(I))='-H'Then Begin
AttrRemove:=Hidden;
IsAttrSetting[I]:=True;
End
Else
If StrToUpper(ParamStr(I))='+A'Then Begin
AttrAdd:=Archive;
IsAttrSetting[I]:=True;
End
Else
If StrToUpper(ParamStr(I))='-A'Then Begin
AttrRemove:=Archive;
IsAttrSetting[I]:=True;
End
Else
If StrToUpper(ParamStr(I))='+S'Then Begin
AttrAdd:=SysFile;
IsAttrSetting[I]:=True;
End
Else
If StrToUpper(ParamStr(I))='-S'Then Begin
AttrRemove:=SysFile;
IsAttrSetting[I]:=True;
End
Else
If StrToUpper(ParamStr(I))='/S'Then Begin
SubDirectory:=True;
IsAttrSetting[I]:=True;
End;
End;
For I:=1to ParamCount do Begin
If Not IsAttrSetting[I]Then Begin
SetAttributFiles(ParamStr(I));
End;
If I=255Then Exit;
End;
End;
END.