06-18-2015 01:26 PM
I'm trying to get the directory listing of shape files on Linux. When I do it on windows this code works, but I can't find the equivalent for Linux.
Filename filelist pipe "dir /b /s c:\temp\*.shp";
data shapefiles ;
infile filelist truncover ;
input filename $100. ;
I know linux uses ls for listing, but I'm not sure how to use it within the filename statement or do I have to use a different approach?
I'm using SAS 9.3 (TS1M2) on linux
06-18-2015 01:50 PM
Thank you for your help. I was able to figure it out taking this approach.
data temp (keep=fname) ;
rc=filename("filelist", "~/shape/") ;
do i=1 to nf;
if ext = 'shp' then output ;
Do you see any issues by taking this approach?
06-18-2015 01:53 PM
There is absolutely nothing wrong with using the external file information functions. The PIPE options are really more useful when you have to run another program that directs output to standard output.
06-18-2015 02:00 PM
I would be a little more careful in determining the extension. Unix files could have no extension or even not have a dot at all. Or could have the dot as the first character.
if 1 < index(fname,'.') < length(fname) then ext=scan(fname,-1,'.');
else ext=' ';
06-19-2015 02:09 AM
The UNIX ls option for recursive listing of subdirectories is -R. You might also look at using the find command for your purpose, as it is much more powerful.
Keep in mind that using wildcards (? or *) in the command on UNIX may produce unexpected results, as the wildcards are expanded by the shell (unsing the contents of the current working directory) before handing off the commandline options to the command itself. Using the find command and -name \*.shp may be better. (the backslash prevents the shell from expanding the wildcards)