Retrieve file size or last modified date of an external file1 min read

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 'https://b-cdn.net/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 2

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
by Subhro Kar
Been in the realm with the professionals of the IT industry. I am passionate about Coding, Blogging, Web Designing and deliver creative and useful content for a wide array of audience.

1 thought on “Retrieve file size or last modified date of an external file<span class="wtr-time-wrap after-title"><span class="wtr-time-number">1</span> min read</span>”

Leave a Comment

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

Share via
Copy link
Powered by Social Snap