Retrieve file size or last modified date of an external file

1
43

The FINFO functions return the value of a file specified. You can get six attributes named ‘info items’ through the use of the FINFO function.

filename fileref '/folders/myfolders/numerical.sas';                                                                                                          
data a(drop=fid);                                                                                                                       
   infile fileref truncover obs=1;                                                                                                       
   fid=fopen('fileref');
   Bytes=finfo(fid,'File Size (bytes)');                                                                                                 
   crdate=finfo(fid,'Create Time');                                                                                                      
   moddate=finfo(fid,'Last Modified');                                                                                                   
run;                                                                                                                                    
                                                                                                                                        
proc print;                                                                                                                             
run;
Retrieve file size or last modified date of an external file 1

To read multiple within a directory, the DOPEN, DNUM and DREAD functions can be used.

The DOPEN function is similar to the FOPEN function and it returns a directory identifier that allows the directory to be opened for input.

The DNUM function counts the number of files within the opened location. You can use this to loop through all the files in a location.

DREAD is used to read each file within the directory. This makes each file accessible for the FOPEN and FINFO functions.

data fileinfo(kepp=filename file moddate);
 filename files '/folders/myfolders';
 dirid=dopen('files');
 countfiles=dnum(dirid);
 do i=1 to countfiles;
  filename=dread(dirid, i);
  file='/folders/myfolders/'||filename;
  sysrc=filename('fnames', file);
  fid=fopen('fnames');

  if fid ^=0 then
   do;
    moddate=finfo(fid, 'Last Modified');
    output;
    sysrc=close(fid);
   end;
 end;
 rc=dclose(dirid);
run;
fopen

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.