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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 830 views
  • 3 likes
  • 3 in conversation