Dir Up/Dir Down

These functions dont physically move up or down a directory tree, as there is no native directory functionality. They merely manipulate the directory string. The directory, or a file attached to the directory string, can then be opened at the desired level.

Qdos users will have to find a work-around for DMEDIUM_DRIVE$

10 rem + ------------------------------------------------------------------------ +
11 rem |<                                 Dir Up                                 >|
12 rem + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +
13 rem |                      "Move" up one directory level                       |
14 rem |                                                                          |
15 rem | This routine requires dir$ to contain a valid, existing, directory.      |
16 rem | It will ignore any file name appended to the given directory.            |
17 rem | If dir$ is not a valid directory it is returned unchanged, ie a DATAD$   |
18 rem | fallback is not accepted. (An alternative could be to return blank to    |
19 rem | indicate error, as the same behaviour occurs when top level is reached.) |
20 rem + ------------------------------------------------------------------------ +
21 rem | V0.01, pjw, 2001 Mar 04                                                  |
22 rem | V0.02, pjw, 2014 Jun 14, use filesystem to sort out previous level       |
23 rem | V0.03, pjw, 2019 Mar 28, Reject DATAD$. Requires DMEDIUM_                |
24 rem + ------------------------------------------------------------------------ +
25 :
26 DEFine FuNction DirUp$(dir$)
27 LOCal ch, l%, dr$(36), dv$(5), md$(5)
28 IF LEN(dir$) < 5: RETurn dir$
29 dv$ = dir$(1 TO 5)
30 ch = FOP_DIR(dir$): dr$ = FNAME$(#ch)
31 md$ = DMEDIUM_DRIVE$(#ch) & '_': CLOSE#ch
32 IF NOT (md$ & dr$ INSTR dir$) = 1: RETurn dir$
33 l% = LEN(dr$) - 1: IF l% < 0: RETurn dv$
34 ch = FOP_DIR(dv$ & dr$(1 TO l%))
35 dr$ = FNAME$(#ch): CLOSE#ch
36 IF LEN(dr$) = 0: RETurn dv$
37 RETurn dv$ & dr$ & '_'
38 END DEFine DirUp$
39 :
40 rem + ------------------------------------------------------------------------ +
41 rem |<                                Dir Down                                >|
42 rem + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +
43 rem |                    "Move" down one directory level                       |
44 rem |                                                                          |
45 rem | Does not check whether directory exists or max name length exceeded.     |
46 rem | Always returns trailing underscore.                                      |
47 rem + ------------------------------------------------------------------------ +
48 rem | V0.01, pjw, 2019 Mar 28, Based on earlier models                         |
49 rem + ------------------------------------------------------------------------ +
50 :
51 DEFine FuNction DirDn$(dir$, sub$)
52 LOCal d$(41)
53 IF LEN(dir$) = 0: RETurn ''
54 IF dir$(LEN(dir$)) = '_' THEN
55  d$ = dir$ & sub$
56 ELSE
57  d$ = dir$ & '_' & sub$
58 END IF
59 IF d$(LEN(d$)) = '_': RETurn d$
60 RETurn d$ & '_'
61 END DEFine DirDn$
62 :
63 :
  
Generated with sb2htm on 2019 Mar 28
©pjwitte March 2oi9