How do I read just subdirectory names from a Unix directory

Reply
New Contributor
Posts: 3

How do I read just subdirectory names from a Unix directory

Hi
I want to read the contents of a specified directory in Unix and then write what is found to a a dataset. The code below will do this (for example for a directory called "/myhome" ) but for all the members of the directory (files and sub directories). Hoever what I want is to only retain subdirectories in my list and ignore files - any ideas how to do this  ?
 
I am using Enterprise Guide (v5.1 with SAS 9.3) and dont have access to X commands
 
Thanks in advance
 

data filelist (keep=fname);

rc=filename("mydir", "/myhome");

did=dopen("mydir");

if did>0 then;

do i=1 to dnum (did);

fname=dread(did, i);

output;

end;

rc=dclose(did);

run;

 

Trusted Advisor
Posts: 1,459

Re: How do I read just subdirectory names from a Unix directory

Your code addapted to what you want:

 

data filelist (keep=fname);

rc=filename("mydir", "/myhome");

did=dopen("mydir");

if did>0 then;

do i=1 to dnum (did);

       fname=dread(did, i);

       rc = filename('tmp',fname,,,'mydir');

       fid = fopen('tmp');

       if fid = 0 then output;  /* FOPEN cannot open a directory */

   else fid = fclose(fid);

end;

rc=dclose(did);

run;

 

Ask a Question
Discussion stats
  • 1 reply
  • 140 views
  • 0 likes
  • 2 in conversation