.key DIR
.bra [
.ket ]
.def DIR ""

FailAt 21
Echo >ENV:NDVersion "N-Dex v1.1   © FairWare 1997"

; See if we have a directory to work on, and if not, get one

If "[DIR] A" EQ " A"

   ; There was no parameter passed ...
   RequestFile >Env:NDTheDir SYS: TITLE="Pick a directory" POSITIVE="This one" DRAWERSONLY
   Echo $NDTheDir >ENV:NDGuideDir
   Delete >NIL: ENV:NDTheDir QUIET

Else

   Echo >ENV:NDGuideDir "[DIR]"

EndIf

; Make sure the specified path is not a file

If "$NDGuideDir A" NOT EQ " A"

   CD >ENV:NDOldDir
   CD "$NDGuideDir" >NIL:
   If ERROR

      RequestChoice >NIL: "$NDVersion" "$NDGuideDir*nis not a valid directory!" "Oooops!"

   Else

; Check for and take into account an already existing Index.Guide file

      LAB CheckExists
      If Exists Index.Guide

         List >ENV:NDExDate Index.Guide LFORMAT "%d %t"
         RequestChoice >Env:NDExists "$NDVersion" "$NDGuideDir*nalready contains an Index.Guide*ndated $NDExDate!*nWhat should I do with it?" "Update it|View it|Quit"
         Delete >NIL: ENV:NDExDate QUIET
         If $NDExists EQ "1"    ; Update it

            Delete >NIL: Index.Guide QUIET FORCE
            Skip CheckExists BACK

         Else

            If $NDExists EQ "2" ; View it

               MultiView Index.Guide
               Skip CheckExists BACK

            EndIf

         EndIf

      Else

; Set up the start of the new guide file

         Echo >Index.Guide "@DataBase*n@Author *"$NDVersion*"*n@Node Main *"Index of $NDGuideDir*"*n*n          Files in @{b}$NDGuideDir@{ub} on @{b}" NOLINE
         Echo >ENV:NDDate "`Date`" LEN=18
         Echo >>Index.Guide "$NDDate" FIRST=1 LEN=9 NOLINE
         Echo >>Index.Guide "@{ub}*n"
         Delete >NIL: ENV:NDDate QUIET

; Decide whether .info files are required

         RequestChoice >ENV:NDIcons "$NDVersion" "Should I include icons?" "Yes|No"
         If $NDIcons EQ "0"      ; No Icons

            Echo >ENV:NDExclude "~(#?.info|Index.Guide)"

         Else                    ; Icons required

            Echo >ENV:NDExclude "~(Index.Guide)"

         EndIf
         Delete >NIL: ENV:NDIcons QUIET

; Decide if we should scan recursively down the directory tree

         RequestChoice >ENV:NDRecursive "$NDVersion" "Should I scan sub-directories?" "Yes|No"
         If $NDRecursive EQ "1"     ; They said Yes

            Echo >ENV:NDOptions "ALL FILES SORT N"

         Else                       ; They said No

            Echo >ENV:NDOptions "FILES SORT N"

         EndIf
         Delete >NIL: ENV:NDRecursive QUIET

; List the required files to the guide file, and finish off

         List >>Index.Guide $NDExclude LFORMAT "                  @{*"%s%s*" LINK *"%f%s/main*" 0}" $NDOptions
         Delete >NIL: ENV:NDExclude QUIET
         Delete >NIL: ENV:NDOptions QUIET

         Echo >>Index.Guide "@endnode"
         RequestChoice >NIL: "$NDVersion" "Index.Guide created for*n$NDGuideDir" "Thanks!"

      Endif
      Delete >NIL: ENV:NDExists QUIET

   EndIf
   CD "$NDOldDir"
   Delete >NIL: ENV:NDOldDir QUIET

EndIf
Delete >NIL: ENV:NDGuideDir QUIET
Delete >NIL: ENV:NDVersion QUIET
;$VER: N-Dex v1.1 (17/4/97)
