BookmarkSubscribeRSS Feed
sathya66
Barite | Level 11

Hi all,

I want to delete the folders (want to keep 5 days folders only).

my code is creating folders every day yymmdd10. format.

but I want to keep only 5 days folders only.

my folders are like this

20180419
20180420

20180421
20180423

20180424
20180425

20180426
20180427

20180428
20180429

20180430

 

Thanks,

SS.

 

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like (and you don't mention which os you use so windows assumed):

http://support.sas.com/kb/45/805.html

Filename filelist pipe "dir /b /s c:\temp\*.sas"; 
                                                                                   
Data _null_;                                        
  Infile filelist truncover;
  Input filename $100.;
  if _n_>5 then call execute(cats('%sysexec(del c:/temp/"',filename,'");'));
Run; 

You can change the if as you like, maybe input as date and check if date is today()-5 or less.

sathya66
Barite | Level 11

It is windows.

 I want to delete the folders irrespective of files in those folders.

Below filename statement referring .sas files.

Filename filelist pipe "dir /b /s c:\temp\*.sas";

 

see the attached

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I am not opening zip files.

Just change the filename to point to your area, i.e replace c:/temp with where your folders are located:

Filename filelist pipe "dir /b /s /ad c:\temp\";

Note I added /ad to restrict list to directories only.

sathya66
Barite | Level 11

Thank you,

I think,I have an issue with my sas shortcut.

NOTE: The infile FILELIST is:Unnamed Pipe Access Device,PROCESS=dir /b /s C:\test\.

Thanks,

SS

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I don't know what "I think,I have an issue with my sas shortcut." means?  The note seems correct, assuming all your folders are in c:/test.  Note your missing the /ad, which only gets directories.

Reeza
Super User

You need XCMD enabled to use PIPE commands or to use system commands.

 

options xcmd;

If that errors out, you'll need a different method, most likely using FDELETE instead. It's still possible, just a different approach required.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 904 views
  • 3 likes
  • 3 in conversation