LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 1999, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sat, 6 Nov 1999 18:49:36 -0600
Reply-To:   shiling@math.wayne.edu
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Shiling Zhang <shiling@MATH.WAYNE.EDU>
Organization:   Wayne State University
Subject:   Re: Read PC directories
Comments:   To: "Terjeson, Mark" <TERJEMW@DSHS.WA.GOV>
Content-Type:   text/plain; charset=us-ascii

_all_;

Using 'pipe' plus 'dir/s/b', one can easily to all directories+files and its sub-directories +files.

12 13 filename allfiles pipe 'dir/s/b d:\sas_template'; 14 15 data _null_; 16 length fname $200; 17 infile allfiles truncover end=end; 18 input fname 1-200; /*aviod embeded blanks */ 19 i+1; 20 put '('i +(-1) ')' +2 fname=; 21 if end then put 'TOTAL NUMBER OF DIRS & FILES =' i; 22 run;

NOTE: The infile ALLFILES is: FILENAME=dir/s/b d:\sas_template, RECFM=V,LRECL=256

(1) FNAME=D:\sas_template\mill_txt.sas (2) FNAME=D:\sas_template\Base_array (3) FNAME=D:\sas_template\IML <snip>.................; (301) FNAME=D:\sas_template\Stat\guess.sas (302) FNAME=D:\sas_template\Stat\reg_restrict.sas (303) FNAME=D:\sas_template\Stat\logistic_reg_data (304) FNAME=D:\sas_template\Stat\logistic_thero_app_data TOTAL NUMBER OF DIRS & FILES =304 NOTE: 304 records were read from the infile ALLFILES. The minimum record length was 18. The maximum record length was 57. NOTE: The DATA statement used 4.45 seconds.

Terjeson, Mark wrote:

> Hi Jacques, > > Here is some old code I grabbed: > > 1) that reads just one directory > listing all entries (this one > cannot distinguish which is a > file and which is directory). > > 2) the second data step reads 2- > levels. Note: dirid2 lets you > know if the level1 entry is a > file or directory by checking > to see if it is zero or not. > > You will have to expand the code > to handle multiple layers. These > two were just old pieces I had. > > Hope This is of some Help, > Mark Terjeson > Washington State Department of Social and Health Services > Division of Research and Data Analysis (RDA) > (360) 902-0741 > (360) 902-0705 fax > mailto:terjemw@dshs.wa.gov > > * listing a directory ; > * keeping only .txt names (commented out); > data files(drop=i numsel dirid rc); > rc=filename('dir','c:\temp\'); > dirid=dopen('dir'); > numsel=dnum(dirid); > do i=1 to numsel; > fname=dread(dirid,i); > if fname not in ('.','..') then > do; > * if upcase(substr(reverse(trim(fname)),1,4)) eq 'TXT.' then > output; > output; > end; > end; > rc=dclose(dirid); > run; > > proc print data=files; > run; > > * listing two levels (only) ; > data files(keep=curdir fname); > > length curdir $200; > > curdir1='c:\temp\'; > rc1=filename('dir1',curdir1); > dirid1=dopen('dir1'); > numsel1=dnum(dirid1); > do i=1 to numsel1; > fname1=dread(dirid1,i); > if fname1 not in ('.','..') then > do; > link subdir; > end; > end; > rc1=dclose(dirid1); > > return; > > subdir: > curdir2=trim(curdir1)||trim(fname1)||'\';; > rc2=filename('dir2',curdir2); > if rc2 ne 0 then > do; > return; > end; > dirid2=dopen('dir2'); > if dirid2 eq 0 then > do; > curdir = curdir1; > fname = fname1; > output; > return; > end; > numsel2=dnum(dirid2); > do j=1 to numsel2; > fname2=dread(dirid2,j); > if fname2 not in ('.','..') then > do; > curdir = curdir2; > fname = fname2; > output; > end; > end; > rc2=dclose(dirid2); > return; > > run; > > proc print data=files; > run; > > > -----Original Message----- > > From: Jacques Thibault [SMTP:JacquesT@IPRONLINE.COM] > > Sent: Friday, November 05, 1999 9:27 AM > > To: SAS-L@LISTSERV.UGA.EDU > > Subject: Read PC directories > > > > Hi SAS-L, > > > > I'm running SAS 6.12 under a WinNT environment and would like to read a > > specific directory and all it sub-directories, from a SAS program. I'm > > not > > sure if I can use SYSGET or if I can manage that with an FTP topic... > > > > Any ideas would help, > > Thx


Back to: Top of message | Previous page | Main SAS-L page