List Files

This very short program will list all the files and folders in the root directory c:\. It does this by using Dir$. The first time you call Dir$ you must supply it a path like this: Dir$("c:\*.*"). (The *.* means every file and folder. You could use t* to restrict the command to files starting with t, or *.mbm to search for and file the ends .mbm).

The first matching file is returned. To see if there are more matching files you keep calling Dir$, but without a string parameter like Dir$(""). It will continue to return files matching the orginal file specification until there are no more, and then nothing ("") is returned.

This program displays all the files it finds in c:\. You could use Dir$ to find out if a specific file exists by supplying a specific filename. If a string is returned, it exists, if null ("") is returned then it doesn't.

PROC ListFiles:
Local f$(255)
f$=Dir$("c:\*.*")
While f$<>""
  Print f$
  f$=Dir$("")
Endwh
Get
ENDP
 

Back to RAW Computing

  Psion home page