home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progbas / pbclon18.arj / DIRVIEW.BAS < prev    next >
BASIC Source File  |  1992-05-08  |  3KB  |  92 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |       PBClone  Copyright (c) 1990-1992  Thomas G. Hanlin III         |
  4. '   |                                                                      |
  5. '   +----------------------------------------------------------------------+
  6.  
  7. ' This is another simple demo of the PBClone routines.  It loads an entire
  8. ' directory into memory and displays it.
  9.  
  10. ' Syntax:
  11. '   DIRVIEW filespec
  12.  
  13. ' The filespec may contain wildcards, of course.
  14.  
  15. ' Typically, this would be converted to an .EXE file using these steps:
  16. '    BC DIRVIEW/O;
  17. '    LINK DIRVIEW/EX,,NUL,PBCLONE;
  18.  
  19.    DECLARE FUNCTION ExplainFAttr$ (Attr%, AbbrevLevel%)
  20.    DECLARE SUB FileCount (File$, BYVAL FilAttr%, FilCount%, ErrCode%)
  21.    DECLARE FUNCTION Int2DateSt$ (DateNr%)
  22.    DECLARE FUNCTION Int2TimeSt$ (TimeNr%)
  23.    DECLARE SUB LoadDir (File$, BYVAL FilAttr%, BYVAL DSeg%, BYVAL DOfs%, ErrCode%)
  24.    DECLARE SUB LoadDirAll (File$, BYVAL FilAttr%, BYVAL DSeg%, BYVAL DOfs%, ErrCode%)
  25.  
  26.    DECLARE SUB PrintComma (Number&, FieldLen%)
  27.  
  28.    TYPE DirType
  29.       FilAttr AS STRING * 1
  30.       FilTime AS INTEGER
  31.       FilDate AS INTEGER
  32.       FilSize AS LONG
  33.       FilName AS STRING * 12
  34.    END TYPE
  35.  
  36.    DEFINT A-Z
  37.  
  38.    Cmd$ = LTRIM$(RTRIM$(UCASE$(COMMAND$)))
  39.    IF LEN(Cmd$) = 0 OR INSTR(Cmd$, "/?") > 0 THEN
  40.       PRINT "DIRVIEW: View Directory Demo for PBClone by Thomas G. Hanlin III"
  41.       PRINT
  42.       PRINT "Syntax:"
  43.       PRINT "  DIRVIEW filespec
  44.       PRINT
  45.       PRINT "The filespec may contain wildcards."
  46.       END
  47.    END IF
  48.    IF LEN(Cmd$) THEN
  49.       File$ = Cmd$
  50.    ELSE
  51.       PRINT "Please provide a file specification."
  52.       END
  53.    END IF
  54.  
  55.    SeekAttr = 1 + 2 + 4 + 16
  56.    FileCount File$, SeekAttr, FilCount, ErrCode
  57.    IF ErrCode THEN
  58.       PRINT "Invalid filespec."
  59.       END
  60.    ELSEIF FilCount = 0 THEN
  61.       PRINT "No matching files."
  62.       END
  63.    END IF
  64.  
  65.    DIM FileList(1 TO FilCount) AS DirType
  66.    DSeg = VARSEG(FileList(1))
  67.    DOfs = VARPTR(FileList(1))
  68.    LoadDirAll File$, SeekAttr, DSeg, DOfs, ErrCode
  69.  
  70.    FOR tmp = 1 TO FilCount
  71.       PRINT FileList(tmp).FilName; "   ";
  72.       PrintComma FileList(tmp).FilSize, 14
  73.       PRINT "   "; Int2DateSt$(FileList(tmp).FilDate);
  74.       PRINT "   "; Int2TimeSt$(FileList(tmp).FilTime);
  75.       PRINT "   "; ExplainFAttr$(ASC(FileList(tmp).FilAttr), 2)
  76.    NEXT
  77.  
  78. SUB PrintComma (Number&, FieldLen)
  79.    N$ = LTRIM$(STR$(Number&))
  80.    R$ = ""
  81.    DO WHILE LEN(N$) > 3
  82.       R$ = RIGHT$(N$, 3) + "," + R$
  83.       N$ = LEFT$(N$, LEN(N$) - 3)
  84.    LOOP
  85.    IF LEN(N$) THEN R$ = N$ + "," + R$
  86.    IF RIGHT$(R$, 1) = "," THEN R$ = LEFT$(R$, LEN(R$) - 1)
  87.    IF LEN(R$) < FieldLen THEN
  88.       R$ = SPACE$(FieldLen - LEN(R$)) + R$
  89.    END IF
  90.    PRINT R$;
  91. END SUB
  92.