Sas 列出目录中的所有文件:如何检测结果是文件还是子目录?

Sas 列出目录中的所有文件:如何检测结果是文件还是子目录?,sas,Sas,我有一个小STP,它列出了Unix服务器上给定目录中的所有文件/子目录。 问题是,我的datastep只返回对象的名称,而不返回文件或目录的信息 我试过一些东西,也有一些想法,但非真的是万无一失的,也许有人可以给我一个提示,我如何才能得到这个 到目前为止,我所尝试的: 使用fileexists:对于文件和目录,这将返回true,因此在这里不起作用 检查一个点。可能有没有扩展名的文件(因此没有点),也有名称中有点的目录,所以这不是万无一失的 在sas中使用UnixFunctionalies:这在

我有一个小STP,它列出了Unix服务器上给定目录中的所有文件/子目录。 问题是,我的datastep只返回对象的名称,而不返回文件或目录的信息

我试过一些东西,也有一些想法,但非真的是万无一失的,也许有人可以给我一个提示,我如何才能得到这个

到目前为止,我所尝试的:

  • 使用fileexists:对于文件和目录,这将返回true,因此在这里不起作用
  • 检查一个点。可能有没有扩展名的文件(因此没有点),也有名称中有点的目录,所以这不是万无一失的
  • 在sas中使用UnixFunctionalies:这在我们的服务器上是禁止的,所以我没有选择
  • 打开文件句柄并执行finfo,如果它不是文件,但

    a) 可能是目录或文件之外的其他内容,或者是由于其他原因而发出的警告

    b) 检查警告以检测类型不是一个好的解决方案

下面是我正在使用的代码的一部分:

filename _folder_ "%bquote(&mydirectory/)";
data x (keep=filepath);
  handle=dopen( '_folder_' );
  if handle > 0 then do;
   count=dnum(handle);
   do i=1 to count;
    filepath="&mydirectory"||dread(handle,i);
    output;
   end;
  end;
  rc=dclose(handle);
run;
filename _folder_ clear;

/*this part just makes a macrovariable with all results*/
proc sql noprint;
  select filepath into: fpath separated by '#' from x;
quit;

/* this macro collects some additional fileinformation from all file in macrovariable fpath and creates a HTML-Ouput*/
%FileAttribs;
使用
FILENAME()
函数定义文件的fileref。这将返回一个代码,指示文件是否存在。然后使用
DOPEN()
函数尝试将fileref作为目录打开。这将告诉您该文件是否为目录

例如,这里是我使用的函数样式宏

%macro direxist
/*----------------------------------------------------------------------
Test if directory exists
----------------------------------------------------------------------*/
(path    /* Name of directory to test for existance */
);
/*----------------------------------------------------------------------
Test if directory exists. Returns value 1 or 0.
 1 - Directory exists
 0 - Directory does not exist

Global macro variable SYSRC will be set to 1 when a file is found
instead of a directory.

----------------------------------------------------------------------*/
%local return rc did fileref;
%*----------------------------------------------------------------------
Set up return values as normal failure to find path.
-----------------------------------------------------------------------;
%let return=0;
%let sysrc=0;

%*----------------------------------------------------------------------
If path is not specified or does not exist then return normal failure.
-----------------------------------------------------------------------;
%if (%bquote(&path) = ) %then %goto quit;
%if ^%sysfunc(fileexist(&path)) %then %goto quit;

%*----------------------------------------------------------------------
Try to open it using DOPEN function.
Return 1 if it can be opened.
Otherwise set SYSRC=1 to mean that PATH exists but is not a directory.
-----------------------------------------------------------------------;
%if (0=%sysfunc(filename(fileref,&path))) %then %do;
  %let did=%sysfunc(dopen(&fileref));
  %if (&did) %then %do;
    %let return=1;
    %let rc=%sysfunc(dclose(&did));
  %end;
  %else %let sysrc=1;
  %let rc=%sysfunc(filename(fileref));
%end;

%quit:
%*----------------------------------------------------------------------
Return the value as the result of the macro.
-----------------------------------------------------------------------;
&return
%mend;

对我有用的Ty,在我的宏中已经有了文件名和fopen,但没有想到检查fid