Powered by QM on a Rpi server
About OpenQM
Sales and Downloads
Help and Support

KnowledgeBase 00051: The DIR() Function

Last updated: 22 Jul 2016
Applies to: All versions
Top level index       Full Index Search Tips
Previous article     Next article

This article was originally published as a Tip of the Week.

The DIR() function allows an application to process an operating system directory.

Using the DIR() Function

The syntax of this function is

where PATHNAME is the operating system pathname of the directory to be processed.

The returned value from this function, stored in LIST in the above example, is a dynamic array in which there is a field for each item in the directory. The values in each field are

1The file or directory name of the item described by this field.
2The item type; D for a directory, F for a file.
3Permissions or attributes.
   Unix/Linux: File permissions as a decimal value.
   Windows: File attribute flags:
      A  Archive
      C  Compressed
      H  Hidden
      R  Read-only
      S  System
      T  Temporary
4Date/time modified as an epoch value (release 2.12-7 onwards).

A Simple Directory Listing Program

   s = dir(".") 
   n = dcount(s, @fm) 
   for i = 1 to n 
      display s<i,2> : '  ' : oconv(s<i,4>, 'EDMYTSL[,A3]') : '  ' : s<i,1> 
   next i 
Use of this program might produce output as below.
D  11 Nov 2011 13:57:21  $COMO 
D  24 Oct 2011 14:02:00  $HOLD 
D  21 Jun 2010 20:40:15  $HOLD.DIC 
D  24 Oct 2011 14:02:00  $SVLISTS 
F  18 Oct 2011 14:42:29  AUDIT.LOG 
F  23 Nov 2011 10:58:23  errlog 

Related Articles


Please tell us if this article was helpful
Very     Slightly     Not at all
Email (optional)