-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNODS.PAS
69 lines (62 loc) · 1.63 KB
/
NODS.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
uses dos;
const FOUND : longint = 0;
function unlink(name: string): boolean;
var f : FILE;
begin
assign(f, name);
{$I-}
erase(f);
{$I+}
unlink := ioresult = 0;
end;
procedure search(dir: string; remove: boolean);
var sr : SEARCHREC;
name : string;
begin
findfirst(dir+'*.*', archive + directory, sr);
while doserror = 0 do
begin
if (sr.attr and directory <> 0) and
(sr.name <> '.') and (sr.name <> '..') then
search(dir + sr.name + '\', remove);
if sr.name = 'DS_STO~1' then
begin
name := dir + sr.name;
writeln('==> ', name);
if remove then unlink(name);
inc(FOUND);
end;
findnext(sr);
end;
end;
var drive : char;
path : string;
remove : boolean;
i : byte;
begin
if paramcount = 0 then
begin
writeln('usage: nods [-f] drive');
exit;
end;
remove := false;
for i := 1 to paramcount do
begin
if paramstr(i) = '-f' then
remove := true
else
path := paramstr(i);
if i = 2 then break;
end;
path[1] := upcase(path[1]);
if path[1] in ['A'..'Z'] then
path := path[1] + ':\'
else path := '\';
if remove then
writeln('cleaning up all DS_STORE on ', path, '...')
else writeln('scanning for DS_STORE on ', path, '...');
search(path, remove);
if remove then
writeln('removed ', FOUND, ' file(s)')
else writeln('found ', FOUND, ' file(s)');
end.