Get PC files from a folder and all sub-folders

Getting the P/C file names in a folder and all of its sub-folders can assist in finding out if a specific file exists or in generating a macro variable parameter list to complete a variety of functions on each file.

To see how to generate and use a macro variable, click here Create macro variable array from SAS variable

Getting the P/C file names in only one folder click here Get PC Files From a folder

FILENAME DIRLIST pipe "dir '&SEL_FOLDER' /s"; RUN ; DATA FILES (KEEP=FOLDER FILE_NAME BYTES DATE TIME) ; RETAIN FOLDER ; RETAIN MFOLDER ; length BUFFER $256 ; infile dirlist length=reclen END=EOF ; input BUFFER $varying256. reclen ; if BUFFER=' ' THEN DELETE ; IF INDEX(UPCASE(BUFFER),"<DIR>") THEN DELETE; FORMAT BYTES COMMA15. FOLDER FILE_NAME $256. ; FORMAT DATE MMDDYY10. TIME TIME5. ; LFOLDER=LENGTH(FOLDER) ; IF LFOLDER>MFOLDER THEN MFOLDER=LFOLDER; IF EOF THEN DO ; CALL SYMPUT("MFOLDER",SUBSTR(LEFT(PUT(MFOLDER,31.)),1, LENGTH(LEFT(PUT(MFOLDER,31.))))) ; END ; DROP LFOLDER MFOLDER ; IF INDEX(UPCASE(BUFFER),'FILE(S)') OR INDEX(UPCASE(BUFFER),'DIR(S)') OR INDEX(UPCASE(BUFFER),'TOTAL FILES LISTED') OR UPCASE(SCAN(BUFFER,1,' ')) ='VOLUME' THEN DELETE ; IF SCAN(BUFFER,1,' ')='Directory' AND SCAN(BUFFER,2,' ')='of' then DO ; FOLDER=SUBSTR(BUFFER,14) ; IF SUBSTR(FOLDER,1,1)=' ' THEN FOLDER=SUBSTR(FOLDER,2) ; END ; ELSE DO ; BYTES=INPUT(COMPRESS(SCAN(BUFFER,4,' '),',') ,20.) ; FILE_NAME=SCAN(BUFFER,5,' ') ; DATE=INPUT(SCAN(BUFFER,1,' '),MMDDYY10.) ; TIME=INPUT(SCAN(BUFFER,2,' '),TIME5.) ; IF SCAN(BUFFER,3,' ')='PM' AND INDEX(SCAN(BUFFER,2,' '),'12:')=0 THEN TIME=TIME+(12*60*60) ; OUTPUT ; END ; RUN ; %PUT %STR(MFOLDER=&MFOLDER) ;