Traversing a directory tree is a core function of many utilities. (Ideally, of course, the OS should have provided a means to do this from the start, abstracted from the nitty-gritty of systems implementation. Now we are stuck with our 36 character directory-plus-filename length limit and that awkward file header.)
This recursive routine does exactly that, and will (with any luck!) clone a complete drive or directory tree. It works on a top-down principle, ie directories are created before the files that go in them are copied.
However, it is not a complete, error trapped program! You should keep backups of everything that is important to you!
Use at own risk!
In particular, it cannot, without modification, be used to copy a directory sub tree to a different directory sub tree without caution. Things like name length issues come into play. So experiment with it in safe circumstances until you know how it works.
Note that you need to supply the source sub tree separately, so if you want to copy win1_docs_ to win2_txt_ you need to specify it thus:
12 source$ = 'win1_': dir$ = 'docs_' 13 target$ = 'win2_txt_'
..and remember the terminating underscores!
10 REMark QLone a drive 11 : 12 source$ = 'ram1_': dir$ = '' 13 target$ = 'ram2_' 14 : 15 CLS 16 PRINT 'Press <ENTER> to clone'! source$; dir$! 'to'! target$!: INPUT r$ 17 IF r$ <> '': STOP 18 : 19 dcount = 0: fcount = 0: ttaken = DATE 20 ERT QLone(source$, dir$, target$) 21 PRINT\ 'Done!' 22 PRINT dcount! 'directories created'\ fcount! 'files copied' 23 PRINT 'Time taken'! (DATE - ttaken);'s' 24 : 25 : 100 rem + ------------------------------------------------------------------------ + 110 rem |< QLone >| 120 rem + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 130 rem | Clone a device or directory sub tree | 140 rem | | 150 rem | Scan source directory tree and create correponding structure under | 160 rem | target. Backup files, maintaining date | 170 rem | | 180 rem | GLObal dcount, fcount, ttaken | 190 rem + ------------------------------------------------------------------------ + 200 rem | V0.00, pjwitte, January 30th 2015 | 210 rem | V0.01, pjw, January 6th 2017, Sans FUPDT(), maintain FBKDT | 220 rem | V0.02, pjw, January 7th 2019, COPY_H -> COPY_O | 230 rem + ------------------------------------------------------------------------ + 240 : 250 DEFine FuNction QLone(sdv$, dir$, tdv$) 260 LOCal ch, lp, fl, ps, er, dt, bd, ty%, nm$(36) 270 ch = FOP_DIR(sdv$ & dir$): IF ch < 0: RETurn ch 280 : 290 ps = 0: er = 0: fl = FLEN(#ch) 300 REPeat lp 310 IF ps >= fl: EXIT lp 320 GET#ch\ ps + 14; nm$ 330 IF LEN(nm$) THEN 340 BGET#ch\ ps + 5, ty% 350 IF ty% = 255 THEN 360 PRINT 'Creating: >'! tdv$; nm$ 370 er = FMAKE_DIR(tdv$ & nm$): IF er = -8: er = 0 380 IF er < 0: RETurn er 390 dcount = dcount + 1 400 er = QLone(sdv$, nm$, tdv$) 410 ELSE 420 PRINT 'Copying:'! sdv$; nm$! '..' 430 LGET#ch\ ps + 52; dt 440 LGET#ch\ ps + 60; bd 450 COPY_O sdv$ & nm$ TO tdv$ & nm$ 460 SET_FUPDT \tdv$ & nm$, dt 470 IF bd: SET_FBKDT \tdv$ & nm$, bd 480 fcount = fcount + 1 490 END IF 500 END IF 510 IF er < 0: EXIT lp 520 ps = ps + 64 530 END REPeat lp 540 CLOSE#ch 550 RETurn er 560 END DEFine QLone 570 : 580 :