Jump to content
Macro Express Forums

Delete Files Based On Date


randallc

Recommended Posts

"Tech"

I'm just trying to get a handle on writing some macros and am not sure how

to proceed in a couple of instances.

I have a folder that I would like to have a macro check the number of files

within it and if it is greater than 3 delete the remaining files based on

the date. Any files older than the third oldest file would be deleted.

Any assistance would be greatly appreciated.

Cheers.

Terry

I know that there was an answer from Joe Wienpert about this on the old Newsgroups;

From: Joe Weinpert "

Subject: Re: Delete files based on date and/or number of files in folder

Date: 04/22/2004

Hello Terry!

Counting the number of files in a folder is straightforward. The first macro here does the job.

The second macro deletes files greater than 60 days old. I have included the code so you can copy and paste it. You will, of course, have to change the target folder.

The other question about deleting files earlier than the 3rd oldest file is more involved, but is doable using the same concepts as shown here. Let the newsgroup if you need more help with it.

{ Joe Weinpert }

<REM2:Count the number of files in a folder_><IVAR2:01:01:0><REP3:07:000002:000001:0001:0:01:C:\Images><NMVAR:08:01:0:0000001:0:0000000><ENDREP><REM2:_><REM2:Delete files older than 60 days from today_><DT:YYYYmmdd_T:10:3:{P00060}{P00000}{P00000}{P00000}><REP3:07:000002:000001:0001:0:01:C:\Copy of Images><VFFILE:0:1:T:2:T:3:T:1:F:1:F:1:F:1:%T1%><NMVAR:05:01:0:0000011:0:0000000><NMVAR:05:02:0:0000012:0:0000000><NMVAR:05:03:0:0000013:0:0000000><TMVAR2:14:11:00:004:000:><TMVAR2:14:12:00:002:000:><TMVAR2:14:13:00:002:000:><TMVAR2:21:11:00:000:000:%T11%_%T11%%T12%%T13%_><TMVAR2:21:11:01:000:000: _0_><IFVAR2:4:11:3:T10_><WFREADY:000000:000002:000000_%T1%><DOFILE:08:NN:%T1%>><REP3:08:000002:000002:0001:1:01:N1_><IMSD:25><IFOTH:09:2:%T1%><EXITREP><ENDIF><ENDREP><ENDIF><ENDREP>

The date format function with Direct Editor gives a shorter, way, and I thought some might be interested; using...

Variable Set From File Date/Time

  Variable Set String %T31% "<DT:yyyyMMddhhnnssz\sT:11:2:%N3%/%N2%/%N1%\s%N4%:%N5%:%N6%>"

  Run Macro in Variable %T31%

The attached macro shows this in more detail, though only makes a file showing those which would be deleted until you would activate it!

Randall

EDIT - PS

If you want exactly 24 hours, use original version here, else if you want "more than one Date" ago; use "yyyyMMMdd" as in the link below.

Delete All Folders older than 1 day (date)

You can make it recursive through subfolders too, if you change the "Repeat with Folder" line appropriately.

Let me know if problems.

Best, Randall

DeleteByFileDate.mxe

Edited by randallc
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...