-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile.ps
40 lines (36 loc) · 877 Bytes
/
file.ps
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
% PostScript File Procedures
% by Raymond Luckhurst, scriptit.uk
% get path dirname
% <path> dirname <string>
/dirname {
dup { (/) search { pop pop }{ exit } ifelse } loop
length 1 index length exch sub 0 exch getinterval
dup length 0 eq { pop (.) } if
} bind def
% get path basename minus suffix
% <path> <suffix> basename <string>
/basename {
exch { (/) search { pop pop }{ exit } ifelse } loop
dup 3 -1 roll
search { 3 1 roll pop length 0 eq { exch } if } if pop
} bind def
% primitive directory test
% <path> isdir <bool>
/isdir {
dup status { % exists
pop pop pop pop
(.) basename length 0 eq % test for no last path component
}{
pop false
} ifelse
} bind def
% primitive file test
% <path> isfile <bool>
/isfile {
dup status { % exists
pop pop pop pop
(.) basename length 0 ne % test for a last path component
}{
pop false
} ifelse
} bind def