List files with full path (Unix)

This code is also available in: Deutsch Español Français
Difficulty Level
Beginner
Published on :
Attention : This code requires administrator privileges.
This macro executes a Unix shell command to list files that match a specified pattern (e.g., /path/*.sas©). It is designed for Unix environments. The result is a character string containing the list of file paths, where each path is complete and enclosed in double quotes, which allows for proper handling of file names containing spaces. The macro relies on another non-standard macro, `%qreadpipe`, to execute the system command.
Data Analysis

Type : EXTERNE


The macro does not use SAS datasets. It interacts directly with the OS file system (Unix) to list its contents via a shell command. The source of the information is therefore the operating system.

1 Code Block
Macro
Explanation :
The code defines a `%lsfpq` macro that accepts a directory path with a file pattern (`dir`). It uses the `%qreadpipe` macro to execute a Unix shell command. This command (`for fn in ...`) iterates through all files matching the provided pattern, then displays each file name with its full path, enclosed in quotes. The `%unquote` function cleans the final result to return it as a simple character string.
Copied!
1%macro lsfpq(dir);
2%unquote(%qreadpipe(for fn in %sysfunc(dequote(&dir)) ;
3DO echo \"$fn\" ;
4done))
5%mend lsfpq;
6 
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : This is public domain software. No guarantee as to suitability or accuracy is given or implied. User uses this code entirely at their own risk.


Related Documentation

Aucune documentation spécifique pour cette catégorie.