Home
CBM
  ASCII-X
  BASIC
    Disk Commands
    Enter RUN mode
    Program Format
    Secret Variables
    Variable Format
    Expressions
    Keywords
      (divide)
      (equal)
      (less)
      (minus)
      (more)
      (multiply)
      (plus)
      (power)
      Abs
      And
      Append
      Asc
      Atn
      Auto
      Backup
      Bank
      Begin
      Bend
      Bload
      Boot
      Box
      Bsave
      Bump
      Catalog
      Char
      Chr
      Circle
      Close
      Clr
      Cmd
      Collect
      Collision
      Color
      Concat
      Cont
      Copy
      Cos
      Data
      Dclear
      Dclose
      Dec
      Def
      Delete
      Dim
      Directory
      Dispose
      Dload
      Do
      Dopen
      Draw
      Ds
      Ds string
      Dsave
      Dverify
      El
      Else
      End
      Envelope
      Er
      Err
      Exit
      Exp
      Fast
      Fetch
      Filter
      Fn
      For
      Fre
      Get
      Get num
      Getkey
      Go
      Gosub
      Goto
      Graphic
      Gshape
      Header
      Help
      Hex
      If
      Input
      Input num
      Instr
      Int
      Joy
      Key
      Left
      Len
      Let
      List
      Load
      Locate
      Log
      Loop
      Mid
      Monitor
      Movspr
      New
      Next
      Not
      Off
      On
      Open
      Or
      Paint
      Peek
      Pen
      Pi
      Play
      Pointer
      Poke
      Pos
      Pot
      Print
      Print num
      Pudef
      Quit
      Rclr
      Rdot
      Read
      Record
      Rem
      Rename
      Renumber
      Restore
      Resume
      Return
      Rgr
      Right
      Rlum
      Rnd
      Rreg
      Rspcolor
      Rsppos
      Rsprite
      Run
      Rwindow
      Save
      Scale
      Scnclr
      Scratch
      Sgn
      Sin
      Sleep
      Slow
      Sound
      Spc
      Sprcolor
      Sprdef
      Sprite
      Sprsav
      Sqr
      Sshape
      St
      Stash
      Step
      Stop
      Str
      Swap
      Sys
      Tab
      Tan
      Tempo
      Then
      Ti
      Ti string
      To
      Trap
      Troff
      Tron
      Until
      Using
      Usr
      Val
      Verify
      Vol
      Wait
      While
      Width
      Window
      Xor
    Syntax
    Tokens
  C128
  D64plus
  Disk
  Escape Codes
  Hardware
  PCxface
  PETSCII
  Pet2asc
Futurama
IBM PC-AT
Contact
Games
Glossary
Hall of fame
Hall of shame
Miscellaneous
Privacy policy
Programming
Twisty puzzles
KeywordAbbreviationToken (hex)Version(s)Classification
DIRECTORYDI{Shift+R}DA4.xCommand and Statement
SOUNDS{Shift+O}DA3.5, 7.0Command and Statement
DIRECTORYDI{Shift+R}EE3.5, 7.0Command and Statement

 Syntax  
DIRECTORY [ search ] [ , D driveNumber ] [ { , | ON } U unitNumber ] ... [ , ItwoChar ] [ , R ] ...
 
ParametersTypeLegal Value(s)Default ValueNote(s)
searchString 1~16 characters  Non-literal must be enclosed in parentheses ()
Not allowed in version 4.0
driveNumberInteger 0 or 1 Non-literal must be enclosed in parentheses ()
unitNumberInteger 8 ~ 11 Non-literal must be enclosed in parentheses () 
twoCharChar[2] any  Must be two literal characters. 
 
 
 Purpose 
List a "disk directory" to the current output device.

 
 Remarks 
DIRECTORY is identical to CATALOG, except for (obviously) the name and the token used to encode the keyword.  DIRECTORY is available version 3.5 but CATALOG is not.  Unlike the similar LOAD"$" command, DIRECTORY does not affect the BASIC program in memory (if any).  DIRECTORY will always specify driveNumber in the command sent to the device (defaults to 0 if you omit it) and so you only get a listing for one drive, while LOAD without a driveNumber will list all files in both drives (assuming the device has 2 drives).
 
The biggest problem with DIRECTORY is the results are only sent to the active output channel (usually the text screen), so the results are not usuable by a program!  One kludgy alternative (if you have write access to a storage medium) is to OPEN a (temporary) sequential-type file for writing.  Then use CMD to direct output to that file.  Then you can open the sequential file and parse through it... yuck!  It would be faster by the way, to OPEN the $ file (the directory listing) for reading and parse it directly, but still yucky.  Note you can use the first method (OPEN/CMD) to direct the DIRECTORY listing to a printer; although not useful for a program, humans seem to like paper listings.
 
Attempting to supply a search parameter will cause SYNTAX ERROR in version 4.0.
 
Without a search parameter, the device will usually list all files in the current directory.  The search parameter can be used to select most subsets of filenames by using wild-cards (* and ? characters).  However, SYNTAX ERROR will be generated if the first character of search is an @.  This is a bug in my opinion because a "disk" (real or some modern equivalant) can have files which begin with an @.
 
If the search has more than 16 characters then STRING TO LONG ERROR will be generated instead.  If search has zero characters then MISSING FILE NAME ERROR occurs (this is not the same as completely omitting the search parameter).
 
Most disk devices also allow your search to restrict the listing to one type of file by appending ",type" to the end of search where type is a character "C", "D", "P", "R", "S", or "U" corresponding to CBM file types of CBM (1581-partition), DEL, PRG, REL, SEQ, or USR (respectively).  However, BASIC does not allow search to be an extra 2 characters in length in such cases (16 is still the limit).  Also DEL will only select specially hacked DEL files; files that have been normally deleted (scratched) will never show up in a directory listing.
 
If no files in the (current) directory match the search or the directory has no files at all, the device will typically report only the disk name and the number of free blocks.  A "block" is a CBM file allocation unit of 256 bytes, 254 of which are available for user data in normal files.  In other words, 4 blocks are about 1 KB and 4096 blocks are about 1 MB.  The directory format uses 2-byte binary encoding of block sizes, which means the maximum size that can be reported is 65535 blocks or about 16 MB.  Some devices (like MMD / SD2IEC) allow files larger than this, so you should be suspicious when you see the number 65535 in a listing; the real value is probably larger.
 
If the device didn't like your search parameter (or perhaps the driveNumber) then typically nothing will be listed by CATALOG.  Check the device error channel with DS$ for a message.  The device might generate an error in other cases (like a physical error attempting to read the storage medium) in which case the listing may abruptly end.  In such cases BASIC will not report an error.  The "solution" is (again) check the device status with DS or DS$.
 
If an expression (enclosed in parentheses) is not valid, or an expression is used without parentheses, SYNTAX ERROR occurs.  If any parameter is not the correct type (string or numeric) a TYPE MISMATCH ERROR will be generated.  Otherwise if a parameter is not a legal value (see table above), an ILLEGAL QUANTITY ERROR is usually generated (except the previosuly described search).
  
Like all disk commands and statements, the Syntax is more flexible than shown above.  In particular, the parameters may be given in any order.  The general restrictions are: a comma (,) must not precede the first parameter (however ON may), any non-literal value (a variable name or expression) must be enclosed in parentheses (), and do not supply the same parameter more than once.  Exceptions include the U and R parameters, which may used an unlimited number of times (R is ignored and the last unitNumber is used), and the twoChar parameter which must always be two literal characters (for DIRECTORY, it is ignored too, but it may not be repeated).
 
Like all disk-based commands, DIRECTORY restricts the driveNumber to 0 or 1 which often makes it unusable on a "disk" with multiple partitions.  Like all disk-based commands, DIRECTORY restricts the "command string" (typically a fileName, but search in this case) to no more than 16 characters which makes it nearly useless if you want to include a path.  However most devices do not allow you to search across multiple paths anyway (I guess the file system driver of VICE would be the only exception).
 
Like all disk-based commands, DIRECTORY will reset DS$ and set the secret variable "DosFA" to the unitNumber.  It also indirectly updates ST.
 
Examples:
DIRECTORY             : REM all files on unit 8, drive 0
DIRECTORY "MAP*" , D1 : REM all file names starting with 'MAP' on unit 8 drive 1
DIRECTORY (S$), U(U)  : REM use variables for search and unit on drive 0
DIRECTORY "*=S"       : REM all SEQ files on unit 8, drive 0
OPEN 1,4: CMD 1: DIRECTORY: PRINT#1 : CLOSE 1 : REM send directory to printer
 
 
 Compare With 
 
 Contrast With 
 See Also 
CMDDS, DS$, ONST
© H2Obsession, 2014