问题描述
我正在尝试使用 Pipe 命令读取带有 zip 文件的文件夹.但是我收到错误说 ls 命令无法识别.文件夹/PROD/
中实际上有2个zip文件(ABC_*.zip)有人可以帮我吗?
I am trying to read the folder with zip files using Pipe Command. But I get error saying ls command not recognized. There are actually 2 zip files(ABC_*.zip) in the folder /PROD/
Can anybody help me in this?
%let extl_dir=/PROD/ ;
filename zl pipe "ls &extl_dir.ABC_*.zip";
data ziplist_a;
infile zl end=last;
length path $200 zipnm $50 filedt $15;
input path $;
zipnm=scan(path,-1,"/");
filedt=scan(scan(path,-1,"_"),1,".");
call symput('zip'||left(_n_), zipnm);
call symput('path'||left(_n_), path);
call symput('filedt'||left(_n_),filedt);
if last then call symput('num_zip',_n_);
*call symput('flenm',filenm);
run;
推荐答案
SAS 发布了一个方便的宏来列出目录中不依赖运行外部命令的文件.可以在此处找到.我更喜欢这种方法,因为它不会引入可能错误的外部来源,例如用户权限、管道权限等.
SAS has published a convenient macro to list files within a directory that does not rely upon running external commands. It can be found here. I prefer this approach as it does not introduce external sources of possible error such as user permissions, pipe permissions etc.
宏使用数据步函数(通过%sysfunc
)并且可以从数据步以相同方式调用命令.下面是一个提取瓦片信息的例子.
The macro uses datastep functions (through %sysfunc
) and the commands can be called in the same manner from a datastep. Below is an example which extracts tile information.
%let dir = /some/folder;
%let fType = csv;
data want (drop = _:);
_rc = filename("dRef", "&dir.");
_id = dopen("dRef");
_n = dnum(_id);
do _i = 1 to _n;
name = dread(_id, _i);
if upcase(scan(name, -1, ".")) = upcase("&fType.") then do;
_rc = filename("fRef", "&dir./" || strip(name));
_fid = fopen("fRef");
size = finfo(_fid, "File Size (bytes)");
dateCreate = finfo(_fid, "Create Time");
dateModify = finfo(_fid, "Last Modified");
_rc = fclose(_fid);
output;
end;
end;
_rc = dclose(_id);
run;
这篇关于使用 SAS 在 UNIX 上读取文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!