From: Red Eagle on
The following code reads a directory and places all the filenames into a SAS
dataset. I would like only file names starting with "ABC" for example. Placing
the selected names into a SLIST would be a bonus. There are no subdirectories
in the directory, so no problem there. SAS 9.1.3 on XP PC. TIA for any
suggestions!

filename _dir_ "&location.";
data filenames(keep=memname);
handle=dopen('_dir_');
if handle > 0 then do;
count=dnum(handle);
do i= 1 to count;
memname=(dread(handle,i));
output filenames;
end;
end;
rc=dclose(handle);
run;
filename _dir_ clear;
%mend;

%get_filenames(C:\temp\);
%get_filenames(C:\temp\ space woman\);

From: PJ on
Please try this one, if this is what you are looking for.

%macro get_filenames(location, pattern);
filename _dir_ "&location.";
data filenames(keep=memname);
handle=dopen('_dir_');
if handle > 0 then do;
count=dnum(handle);
do i= 1 to count;
memname=(dread(handle,i));
if memname = : "&pattern" then output filenames;
end;
end;
rc=dclose(handle);
run;

%global slist;
proc sql;
select memname into :slist separated by " " from filenames order by
memname;
quit;

filename _dir_ clear;
%mend;

%get_filenames(C:\Xuemei_SA\Adv,proc );
%put &slist=;

%get_filenames(C:\Xuemei_SA\Adv,ABC);
%put &slist=;

Regards,
PJ
From: montura on
class
directory;
public num sequence /
(initialValue=2);

public list gParameter / (sendEvent='N');
public list gDirectory / (sendEvent='N');

_init: method /
(state='o');

_super();

gParameter=getniteml(envlist('G'),
'parameter');
gDirectory=getniteml(envlist('G'),
'directory');

endmethod;

runInterface: method / (description='Build a list of subdirectory
names');
dcl num dirID xFile
isDir;
dcl char itemName
fullpath;
dcl char root=getnitemc(gParameter, 'source
root');

filename('rootref',
root);

dirid=dopen('rootref');
do xFile=1 to
dnum(dirid);
itemName=dread(dirid,
xFile);
fullpath=root||"\"||
itemName;

filename('dirref',
fullpath);

isDir=dopen('dirref');

if isDir then do;
* add check for name prefix here ;

insertc(gDirectory, itemName,
-1);

dclose(isDir);

end;

filename('dirref',
'');

end;

dclose(dirid);

filename('rootref', '');

savelist('catalog', 'libname.catalog.memname,slist',
gDirectory);

endmethod;
endclass;


From: montura on
oops - you said just file names, remove the check that limits output
for the directory, IsDIR to get around that.