Macros for SAS Application Developers
https://github.com/sasjs/core
mp_dirlist.sas File Reference

Returns all files and subdirectories within a specified parent. More...

Go to the source code of this file.

Detailed Description

When used with getattrs=NO, is not OS specific (uses dopen / dread).

Credit for the rename approach: https://communities.sas.com/t5/SAS-Programming/SAS-Function-to-convert-string-to-Legal-SAS-Name/m-p/27375/highlight/true#M5003

Usage:

%mp_dirlist(path=/some/location, outds=myTable, maxdepth=MAX)

%mp_dirlist(outds=cwdfileprops, getattrs=YES)

%mp_dirlist(fref=MYFREF)
Warning
In a Unix environment, the existence of a named pipe will cause this macro to hang. Therefore this tool should be used with caution in a SAS 9 web application, as it can use up all available multibridge sessions if requests are resubmitted. If anyone finds a way to positively identify a named pipe using SAS (without X CMD) do please raise an issue!
Parameters
[in]path=(sysfunc(pathname(work))) Path for which to return contents
[in]fref=(0) Provide a DISK engine fileref as an alternative to PATH
[in]maxdepth=(0) Set to a positive integer to indicate the level of subdirectory scan recursion - eg 3, to go ./3/levels/deep. For unlimited recursion, set to MAX.
[in]showparent=(NO) By default, the initial parent directory is not part of the results. Set to YES to include it. For this record only, directory=filepath.
[out]outds=(work.mp_dirlist) The output dataset to create
[out]getattrs=(NO) If getattrs=YES then the doptname / foptname functions are used to scan all properties - any characters that are not valid in a SAS name (v7) are simply stripped, and the table is transposed so theat each property is a column and there is one file per row. An attempt is made to get all properties whether a file or folder, but some files/folders cannot be accessed, and so not all properties can / will be populated.
Returns
outds contains the following variables:
  • directory (containing folder)
  • file_or_folder (file / folder)
  • filepath (path/to/file.name)
  • filename (just the file name)
  • ext (.extension)
  • msg (system message if any issues)
  • level (depth of folder)
  • OS SPECIFIC variables, if getattrs= is used.

SAS Macros

Related Macros

Version
9.2

Definition in file mp_dirlist.sas.