'===========================================================================
' Subject: HTML LISTING OF DIRECTORY          Date: 04-28-99 (07:08)       
'  Author: Alexander Meyer                    Code: QB, QBasic, PDS        
'  Origin: Meyer.Karl@t-online.de           Packet: HTML.ABC
'===========================================================================
'                             ////
'                           0(o o)0
'-------------------------ooO (_) Ooo---------------------
' DIR2HTML.BAS -- Written in QuickBasic 4.5
'        
' Name: HTML listing of directory
' Author: Alexander Meyer
' Date: 04-24-1999
' Description: This program lists all files in one directory
'              to a HTML file.
'
'For questions or comments mail to: Meyer.Karl@t-online.de
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
'
'PLEASE READ FIRST:
'This program uses the DOS command 'DIR' to get a list of the files.
'It only works correct when you've got Windows 95 because the format of
'the DIR listing is a bit different on other systems (and this program
'was made for the Windows 95 DIR format.)
'This program doesn't support long filenames.
'If you run this program from QBasic, you'll get an error message when
'the directory has got more than 355 files. QuickBasic can handle more files.

s$ = "&nbsp;": c$ = CHR$(34)
DIM Filename$(1 TO 1000)
DIM FileSize$(1 TO 1000)
DIM FileDate$(1 TO 1000)
DIM FileTime$(1 TO 1000)
SCREEN 0: CLS
PRINT "HTML listing of directory"
PRINT "By Alexander Meyer 1999"
PRINT
PRINT "Only works correct when you've got Windows 95"
PRINT "Can't handle more than 355 files in QBasic (in QB, it's more)"
PRINT "(see source code for more information.)"
PRINT
INPUT "Directory (with full path): ", Directory$
INPUT "HTML file where the listing will be saved: ", OutFile$
PRINT
PRINT "Working...."
SHELL "DIR " + Directory$ + "\*.* /ON > 0o0o.tmp"
OPEN "0o0o.tmp" FOR INPUT AS #1
  DO WHILE NOT EOF(1)
    INPUT #1, TestLine$
    f% = f% + 1
    TestLine$ = ""
  LOOP
CLOSE #1
f% = f% - 8
OPEN "0o0o.tmp" FOR INPUT AS #1
  DO WHILE NOT EOF(1)
    i% = i% + 1
NextOne:
    LINE INPUT #1, TempLine$
    IF i% >= 8 THEN
      z% = z% + 1
      Filename1$ = RTRIM$(MID$(TempLine$, 1, 8))
      Extension$ = MID$(TempLine$, 10, 3)
      IF Filename1$ = "0O0O" AND Extension$ = "TMP" THEN
        z% = z% - 1: f% = f% - 1
        GOTO NextOne
      END IF
      IfDir$ = MID$(TempLine$, 16, 5)
      IF IfDir$ = "<DIR>" THEN
        Filename$(z%) = Filename1$: NumDirs% = NumDirs% + 1
      ELSE
        Filename$(z%) = Filename1$ + "." + Extension$
      END IF
      Filename$(z%) = RTRIM$(Filename$(z%))
      IF z% = f% THEN
        NumBytes$ = MID$(TempLine$, 29, 14)
        NumBytes$ = LTRIM$(NumBytes$)
        EXIT DO
      END IF
      FileSize$(z%) = MID$(TempLine$, 14, 14)
      FileSize$(z%) = LTRIM$(FileSize$(z%))
      IF IfDir$ = "<DIR>" THEN FileSize$(z%) = "0"
      FileSize$(z%) = RTRIM$(FileSize$(z%))
      FileDate1$ = MID$(TempLine$, 29, 15)
      FileDate$(z%) = MID$(FileDate1$, 1, 8)
      FileTime$(z%) = MID$(FileDate1$, 11, 5)
      FileTime$(z%) = LTRIM$(FileTime$(z%))
    END IF
    TempLine$ = ""
  LOOP
CLOSE #1

NumFiles% = z% - NumDirs% - 1

OPEN OutFile$ FOR OUTPUT AS #1
  PRINT #1, "<HTML>"
  PRINT #1, "<HEAD>"
  PRINT #1, "<TITLE>Contents of directory "; Directory$; "</TITLE>"
  PRINT #1, "</HEAD>"
  PRINT #1, "<BODY>"
  PRINT #1, "<BR><B><FONT SIZE=+2>Directory "; Directory$; "</FONT></B>"
  PRINT #1, "<BR>"; s$
  PRINT #1, "<P><TT>"
  PRINT #1, "Name";
  FOR d% = 1 TO 20: PRINT #1, s$; : NEXT d%
  PRINT #1, "Size";
  FOR d% = 1 TO 2: PRINT #1, s$; : NEXT d%
  PRINT #1, "Date";
  FOR d% = 1 TO 6: PRINT #1, s$; : NEXT d%
  PRINT #1, "Time";
  FOR d% = 1 TO 2: PRINT #1, s$; : NEXT d%
  PRINT #1, "File type"
  PRINT #1, "<HR WIDTH="; c$; "100%"; c$; ">"
  PRINT #1, "<BR><A HREF="; c$; "../"; c$; ">Parent directory</A>"
  FOR d% = 1 TO z% - 1
    PRINT #1, "<BR><A HREF="; c$; Filename$(d%); c$; ">"; Filename$(d%); "</A>";
    FOR e% = 1 TO 14 - LEN(Filename$(d%)): PRINT #1, s$; : NEXT e%
    FOR e% = 1 TO 14 - LEN(FileSize$(d%)): PRINT #1, s$; : NEXT e%
    PRINT #1, FileSize$(d%); s$; s$;
    PRINT #1, FileDate$(d%);
    IF LEN(FileTime$(d%)) = 4 THEN
      PRINT #1, s$; s$; FileTime$(d%);
    ELSE
      PRINT #1, s$; FileTime$(d%);
    END IF
    GOSUB FileType
    PRINT #1, s$; s$; FileType$
    FileType$ = "": Ext$ = "": FileType% = 0
  NEXT d%
  PRINT #1, "<HR WIDTH="; c$; "100%"; c$; ">"
  PRINT #1, NumFiles%; "file(s)";
  FOR e% = 1 TO 14 - LEN(STR$(NumFiles%)) - 7: PRINT #1, s$; : NEXT e%
  FOR e% = 1 TO 14 - LEN(NumBytes$): PRINT #1, s$; : NEXT e%
  PRINT #1, NumBytes$; " bytes"
  PRINT #1, "<BR>"; NumDirs%; "directorie(s)"
  PRINT #1, "</TT>"
  PRINT #1, "</BODY>"
  PRINT #1, "</HTML>"
CLOSE #1
KILL "0o0o.tmp"
PRINT
PRINT "Done!"
PRINT "Now you can view "; OutFile$; " in your browser!"
PRINT "Bye!"
END

FileType:
IF INSTR(Filename$(d%), ".") = 0 THEN
  FileType$ = "Directory"
  RETURN
ELSEIF RIGHT$(Filename$(d%), 1) = "." THEN
  FileType$ = "File"
  RETURN
END IF
FOR e% = 1 TO LEN(Filename$(d%))
  IF MID$(Filename$(d%), e%, 1) = "." THEN FileType% = 1
  IF FileType% = 1 THEN Ext$ = Ext$ + MID$(Filename$(d%), e%, 1)
NEXT e%
SELECT CASE Ext$
  CASE ".EXE", ".COM": FileType$ = "Executable file"
  CASE ".TXT": FileType$ = "Text file"
  CASE ".DOC": FileType$ = "Document file"
  CASE ".BAS": FileType$ = "BASIC file"
  CASE ".ABC": FileType$ = "All Basic Code file"
  CASE ".ASM": FileType$ = "Assembler file"
  CASE ".ZIP": FileType$ = "ZIP archive"
  CASE ".BAT": FileType$ = "Batch file"
  CASE ".HTM": FileType$ = "Hypertext markup language"
  CASE ".WAV": FileType$ = "Wave file"
  CASE ".MID": FileType$ = "MIDI music file"
  CASE ".VOC": FileType$ = "Creative Voice File"
  CASE ".MP3": FileType$ = "MP3 music file"
  CASE ".GIF": FileType$ = "GIF picture"
  CASE ".JPG": FileType$ = "JPEG picture"
  CASE ".BMP": FileType$ = "Bitmap picture"
  CASE ".DAT": FileType$ = "Data file"
  CASE ".HLP": FileType$ = "Help file"
  CASE ".TMP": FileType$ = "Temporary file"
  'You can add your file types here. Be sure that you've got the '.'
  'at the beginning of each extension.
  CASE ELSE: FileType$ = MID$(Ext$, 2, LEN(Ext$) - 1) + " file"
END SELECT
RETURN
