PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Walking a directory structure  (Read 1547 times)

PxPlus

  • Administrator
  • Diamond Member
  • *****
  • Posts: 1091
    • View Profile
Walking a directory structure
« on: May 31, 2018, 10:34:58 AM »
When reading a directory, subdirectory entries can be identified if the system parameter 'SD' is enabled. When 'SD' is set each subdirectory in a directory will have a trailing directory delimiter ('\' for Windows, '/' for Unix and Linux).

The following logic uses this in order to walk and process a directory structure:

0010 LET SV_SD=PRM('SD')
0020 SET_PARAM 'SD'
0030 LET D$=LWD ! Starting point
0040 GOSUB DO_DIR
0050 SET_PARAM 'SD'=SV_SD; END
0060 !
0070 DO_DIR:
0080 PRINT 'BLUE',D$
0090 SELECT F$ FROM D$ WHERE F$(1,1)<>"."
0100 IF MID(F$,-1)<>DLM THEN GOSUB DO_FILE ELSE GOSUB DO_SUBDIR
0110 NEXT RECORD
0120 RETURN
0130 !
0140 DO_SUBDIR:
0150 LET D1$=D$
0160 LOCAL D$
0170 LET D$=D1$+DLM+STP(F$,1,DLM)
0180 GOSUB DO_DIR
0190 RETURN
0200 !
0210 DO_FILE:
0220 PRINT D$+DLM+F$
0230 RETURN

Note: We also have a routine "dirtree" which can be used, for more information please visit:
https://manual.pvxplus.com/PXPLUS/utilities/dirtree.htm