BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sathya66
Barite | Level 11

All,

Below code give list of files and their sizes but it will not give subfolder size/subfolder file sizes.

is there a way that can read subfolder/file sizes .

we disabled XCMD so need to use this SAS code.

So I am looking for total folder size, subfolder size ,all file lists  and sizes.

%macro getfilesizes(directory, extension, dataset) ;
  data &dataset. ;
    length FILE $256 DTE 8 SIZE 8 DIRECTORY $256 FILRF FILRFB $8 ;
    format DTE datetime.;
    keep FILE DTE SIZE DIRECTORY ;
    DIRECTORY= "&directory";
    RC1      = filename(FILRF,DIRECTORY);
    DID      = dopen(FILRF);
    MEMCOUNT = dnum(DID);
    do I=1 to MEMCOUNT;
      FILE = dread(DID,I);
      if "&extension" = scan(FILE,-1,'.') or "&extension" = "all" then do;
        RC2 =filename(FILRFB, catx('/', DIRECTORY, FILE) );
        FID =fopen(FILRFB);
        if FID then do;
          DTE =input(finfo(FID,'Last Modified'),anydtdtm.);  
          SIZE=input(finfo(FID,'File Size (bytes)'),32.);
        end;
        else call missing(DTE,SIZE);
        output;
        RC3 =fclose(FID);
        RC4 =filename(FILRFB);
      end;
    end;
    RC5=dclose(DID); RC6=filename(FILRF);
  run;

  %mend getfilesizes;
libname test "/test";

%getfilesizes(directory=%sysfunc(pathname(test)), extension=all, dataset=folder_size)

we can calculate file size by using picture format

https://communities.sas.com/t5/SAS-Programming/Proc-report-file-size-in-GBs/td-p/696146

 thanks to @Kurt_Bremser 

1 ACCEPTED SOLUTION
1 REPLY 1

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 5051 views
  • 1 like
  • 2 in conversation