• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Symbol Functions
      • Item Functions
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Case Object
      • Document Object
      • File Object
      • Freq Object
      • Geometry Object
      • HashMap Object
      • Image Object
      • List Object
      • Map Object
      • Path
      • Pff Object
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
      • External File Functions
        • Clear Function
        • Close Function
        • CountCases Function
        • CurrentKey Function
        • DelCase Function
        • DirCreate Function
        • DirDelete Function
        • DirExist Function
        • DirList Function
        • FileConcat Function
        • FileCopy Function
        • FileCreate Function
        • FileDelete Function
        • FileEmpty Function
        • FileExist Function
        • FileName Function
        • FileRead Function
        • FileRename Function
        • FileSize Function
        • FileTime Function
        • FileWrite Function
        • Find Function
        • Key Function
        • KeyList Function
        • LoadCase Function
        • Locate Function
        • NMembers Function
        • Open Function
        • Retrieve Function
        • Set Access Statement
        • SetFile Function
        • Set First Statement
        • Set Last Statement
        • Write Function
        • WriteCase Function
      • Synchronization Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

DirList Function

Format
b = dirlist(list_to_receive_paths, directory_path
           
ʃ, filter := wildcardʅ
           
ʃ, recursive := recursive_flagʅ);
Description
The dirlist function fills list_to_receive_paths, a string List, with the paths of files and directories located in a directory specified by directory_path. The paths included in the List are fully evaluated absolute paths. Hidden and system files are not included in the directory listing.
The directory_path can be one of the following:
  • A string expression specifying a directory.
  • One of the path types documented in the pathname function.
  • A media type, which will list the files of the specified media type on Android. These files can reside in multiple directories.
Using named arguments, you can specify a string expression, wildcard, that is applied to filter the paths added to the string List. For example, "*.csdb" would include only CSPro DB data sources. You can specify multiple wildcard filters by separating each filter with a semicolon. The filter "*.jpg;*.jpeg;*.bmp" would include both JPEG and BMP files. Instead of using a string expression, you can also use a predefined wildcard expression:
  • FileType.Audio: Files that the Audio object can read and write.
  • FileType.Geometry: Files that the Geometry object can read and write.
  • FileType.Image: Files that the Image object can read and write.
By default, only files and directories located in the directory are added to the List. To recursively add paths, creating a listing of the specified directory as well as any subdirectories, set the numeric expression recursive_flag to true.
A directory listing can also be retrieved using the Path.getDirectoryListing action.
Return Value
The function returns a logical value of 1 (true) if successful and 0 (false) if the directory does not exist or cannot be accessed. If the List is read-only, the function returns default.
Example 1
write("Shapefile and tile packages in folder and subfolders:");

List string map_files;

dirlist(map_files, "C:/Survey/Maps", filter := "*.shp;*.tpk", recursive := true);

do numeric ctr = 1 while ctr <= map_files.length()
   
write("%s", map_files(ctr));
enddo;
Example 2
// get a list of all shared images on Android that can be loaded using the image object
List string image_files;

dirlist(image_files, Media.Images, filter := FileType.Image);
See also: Path.getDirectoryListing Action, Path.selectFile Function, DirCreate Function, DirExist Function