DelDir

The example given here deletes the tmp directory - and everything below it - in ram1_tst_. It does not delete ram1_tst_ itself.

10 CLS
11 er = FMAKE_DIR("ram1_tst")
12 er = FMAKE_DIR("ram1_tst_tmp")
13 SAVE_O 'ram1_test_bas'
14 SAVE_O 'ram1_tst_tmp_test_bas'
15 :
16 ERT DelDir(#1; "ram1_", "tst_tmp_", 0)
17 :
100 REMark + ------------------------------------------------------------------------ +
102 REMark |<                                 DelDir                                 >|
104 REMark + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +
106 REMark |                          Delete Directory Tree                           |
108 REMark |                                                                          |
110 REMark | SBASIC only! With slight modification: Qdos + TK2 (+DD2)                 |
112 REMark | Visits every node in the directory tree and, starting from the bottom,   |
114 REMark | deletes each file in it, followed by the containing directory.           |
116 REMark | The silent switch is to turn off messages: 1 => off, 0 => on             |
118 REMark + ------------------------------------------------------------------------ +
120 REMark | V0.06, pjw 2oi9, bugfix: Doesnt delete files if no dir matches spec!!    |
122 REMark + ------------------------------------------------------------------------ +
124 :
126 DEFine FuNction DelDir(ch, fdv$, dir$, silent)
128 LOCal cd, lp, er, fl, ps, ty%, dr$(36), nm$(36)
130 :
132 cd = FOP_DIR(fdv$ & dir$): IF cd < 0: RETurn cd
134 IF dir$ = '_': dr$ = "": ELSE : dr$ = dir$
136 IF LEN(dr$) THEN
138  IF dr$(LEN(dr$)) = '_': dr$ = dr$(1 TO LEN(dr$) - 1)
140  IF NOT FNAME$(#cd) == dr$: CLOSE#cd: RETurn 0
142 END IF
144 ps = 0: er = 0: fl = FLEN(#cd)
146 REPeat lp
148  IF ps >= fl: EXIT lp
150  GET#cd\ ps + 14; nm$
152  IF LEN(nm$) > 0 THEN
154   BGET#cd\ ps + 5, ty%
156   IF ty% = 255 THEN
158    IF NOT silent: PRINT#ch; '>'! fdv$; nm$
160    er = DelDir(#ch; fdv$, nm$): IF er < 0: EXIT lp
162   ELSE
164    IF NOT silent: PRINT#ch; 'x'! fdv$; nm$
166    DELETE fdv$ & nm$
168   END IF
170  END IF
172  ps = ps + 64
174 END REPeat lp
176 CLOSE#cd
178 IF er >= 0 THEN
180  IF NOT silent: PRINT#ch; 'X'! fdv$; dr$; " _"((dr$ <> "") + 1)
182  DELETE fdv$ & dr$: REMark Del DEVn_ is ok
184 END IF
186 RETurn er
188 END DEFine DelDir
190 :
192 :
  
Generated with sb2htm on 2019 Dec 15
©pjwitte March 2oi9