Hi SAS DevTeam!
The DOPEN() and DNUM() functions do not show hidden files in a directory what leads to confusion and "inconsistent" results.
I know the bahavior of the DOPEN() and DNUM() is not a bug but rather a featur, but...
Imagine the following scenario:
User has 5 files in a directory, some of them are hidden, some are not (see Figure 1.).
User copies files form Windows machine to a network drive (on samba).
User runs code collecting files under local Windows folder, gets result X (see Figure 2. and 3., and Snippet 1.).
User runs code collecting files on the network drive, gets resylt Y.
X and Y are different... (see Figure 2.)
User is confused.
The issue grows fast when we are talking not about a single directory, but a whole tree of directories...
Solution: allow DOPEN() and DNUM() to list all files including hidden.
This could be delivered multiple ways:
1) create functions DOPENhidden() and DNUMhidden() that list hidden files,
2) add additional argument to DOPEN() and DNUM() that indicates hidden files listing, or
3) create an option LISTHIDDENFIELS that alters behavior of DOPEN() and DNUM().
All the best
Bart
Figure 1. Files under Windows (C:\test) , their copy on the network drive (TEST), and a view form console on that location (ls - a and ls).
Under Windows files test2.sas and test5.sas are hidden and .test1.sas is not, after copying (because of OSes behavior) test2.sas and test5.sas are no longer hidden, but .test1.sas starts to be.
Figure2.Execution of the file listing code on local (C:\TEST) and the network drive (H:\TEST). DOPEN() and DNUM() return different number of files depending on the location.
Figure 3.Execution of the same code under Linux SAS in SAS studio. (Just for bigger perspective)
Snippet 1. Code collecting files in a directory (parameter path).
%macro test123(path);
%put &=sysvlong4.;
data _null_;
fname="__F__";
rc1=filename(fname,"&path.");
rc1txt=sysmsg();
put rc1= rc1txt=;
rcf = FILEREF(fname);
rcftxt = sysmsg();
put rcf= rcftxt=;
rc2=dopen(fname);
put rc2=;
do i=1 to dnum(rc2) ;
fn=dread(rc2,i) ;
put i= " &path. " fn=;
end ;
rc3=dclose(rc2);
rc1=filename(fname);
run;
%mend test123;
... View more