Jump to content
Macro Express Forums

Delete All Files Older 1 Day


yaqwa

Recommended Posts

can someone please help me. My english is not the very best and i need to create a macro which is to heavvy for me.

 

it is really simple (for those who can do it)

i just want to create a macro which deletes all files in a folder older than 1 day

 

would be nice if someone can help me

 

thanks

Link to comment
Share on other sites

Hi,

Good to see you on the forum!

 

Try this link; the file used to make a list of "files which would be deleted;" ; you must change it to activate it and do the deletion (check it is working appropriately first?)

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

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 link

DeleteByFileDate.mxe

Here's a modification to give you the choice of deleting or not;

// Delete files older than %N99% days from today >

// Demonstrating run Macro in Variable to set comparison Date stamp string from File details

// Uses variables %T1%-T4%,%T11%, %T10%, %T98%, %N99%, %N1%-%N6%

Set Variable %T4% to "Installation Path"

Multiple Choice Menu: Delete the Files in a Folder?

Variable Set String %T98% from Folder Name

Variable Set Integer %N99% to 1

Variable Set Integer %N99% from Prompt

Variable Set String %T11% ""

Variable Set String %T2% "yyyyMMdd"

Variable Modify String: Save %T11% to Text File

Date/Time: Save "%T2%" into %T10%

Repeat with Folder

  Variable Set From File Date/Time

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

  Run Macro in Variable %T31%

  If Variable %T11% < variable %T10%

    If Variable %T3% contains "Delete"

      Wait for File Ready: "%T1%"

      Delete File or Files: "%T1%"

    End If

    // Just make a list of files to be deleted for now

    If Variable %T3% contains "List"

      Variable Modify String: Append %T1% to %T11%

      Variable Modify String: Append %T11% to Text File

    End If

  End If

Repeat End

Program Launch: "DisplayTemp.txt"

Macro Return

<REM2:Delete files older than %N99% days from today >><REM2:Demonstrating run Macro in Variable to set comparison Date stamp string from File details><REM2:Uses variables %T1%-T4%,%T11%, %T10%, %T98%, %N99%, %N1%-%N6%><VSETMISC:T4:Installation Path><MENU2:1:T:03:CenterCenter:Delete the Files in a Folder?Just Make a List or Delete the Files?Just Make a List
Delete the Files
Make List and Delete FilesT><TVAR2:98:10:Set folder for deletion of some files><IVAR2:99:01:1><IVAR2:99:02:FDelete files older than : How many days?FFCenter:Center><TVAR2:11:01:><TVAR2:02:01:yyyyMMdd><TMVAR2:17:11:00:000:000:%T4%\DisplayTemp.txtT><DT:%T2%T:10:3:{P%N99%}{P00000}{P00000}{P00000}><REP3:07:000002:000001:0001:0:01:%T98%><VFFILE:0:1:T:2:T:3:T:1:T:4:T:5:T:6:%T1%><TVAR2:31:01:<DT:%T2%\sT:11:2:%N3%/%N2%/%N1%\s%N4%:%N5%:%N6%>><RUNMACVAR:31><IFVAR2:4:11:3:T10><IFVAR2:1:03:7:TDelete><WFREADY:000000:000002:000000%T1%><DOFILE:08:NN:%T1%>><ENDIF><REM2:Just make a list of files to be deleted for now><IFVAR2:1:03:7:TList><TMVAR2:08:11:01:000:000:><TMVAR2:20:11:00:000:000:%T4%\DisplayTemp.txtT><ENDIF><ENDIF><ENDREP><LAUNCHDEL2:0:01%T4%\DisplayTemp.txt><MRETURN>

DeleteByFileDate2.mxe

Edited by randallc
Link to comment
Share on other sites

  • 9 years later...

The macro was scripted in Macro Express 3, but you are using Macro Express 4 ("Professional"). The syntax of commands is slightly different.

 

Try importing the .mxe file into Version 4 rather than opening it. (I think you may need to rename it to .mex)

 

Alternatively close Macro Express 4, download Macro Express 3, and try again.

Link to comment
Share on other sites

The Run Macro in Variable command allows you to perform actions that may not be possible with the standard macro commands. This command uses the syntax from the Direct Editor. This syntax is not the same between Macro Express 3 and Macro Express Pro and it is not converted when a Macro Express 3 macro is loaded into Macro Express Pro.

 

This macro illustrates this. It was designed to perform some date math to calculate the number of days between two dates. Macro Express Pro has commands that allow you to do this directly using Date/Time variables.

 

Here is the macro modified for Macro Express Pro. I have changed the macro but have not done any testing with it. You may need to make further changes.

 

Copy and paste this into a new Macro Express Pro macro:

<COMMENT Value="Delete files older than %N[99]% days from today >"/>
<COMMENT Value="Demonstrating run Macro in Variable to set comparison Date stamp string from File details"/>
<COMMENT Value="Uses variables %T[1]%-T4%,%T[11]%, %T[10]%, %T[98]%, %N[99]%, %N[1]%-%N[6]%"/>
<VARIABLE SET FROM MISC Destination="%T[4]%" Value="Installation Path"/>
<MULTIPLE CHOICE MENU Style="\x00" Result="\x01" Dest="%T[3]%" Title="Delete the Files in a Folder?" Prompt="Just Make a List or Delete the Files?" Options="Just Make a List\r\nDelete the Files\r\nMake List and Delete Files" Left="Center" Top="Center" Monitor="0" Width="292" Height="150" OnTop="FALSE"/>
<ON ERROR/>
<CATCH ERROR Code="2"/>
<VARIABLE SET STRING Option="\x00" Destination="%T[3]%" Value="CANCEL" NoEmbeddedVars="FALSE"/>
<END CATCH ERROR/>
<END ERROR/>
<VARIABLE SET STRING Option="\x09" Destination="%T[98]%" Value="Set folder for deletion of some files"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[99]%" Value="1"/>
<VARIABLE SET INTEGER Option="\x01" Destination="%N[99]%" Prompt="Delete files older than : How many days?" Mask="FALSE" OnTop="FALSE" Left="Center" Top="Center" Monitor="0"/>
<VARIABLE SET STRING Option="\x00" Destination="%T[11]%" NoEmbeddedVars="FALSE"/>
<VARIABLE SET STRING Option="\x00" Destination="%T[2]%" Value="yyyyMMdd" NoEmbeddedVars="FALSE"/>
<VARIABLE MODIFY STRING Option="\x11" Destination="%T[11]%" Filename="%T[4]%\\DisplayTemp.txt" Strip="FALSE" NoEmbeddedVars="FALSE"/>
<DATE/TIME Format="%T[2]%" Flags="\x82" Date="12/30/1899" Day_Offset="-%N[99]%" Month_Offset="-0" Year_Offset="0" Hour_Offset="-0" Minute_Offset="-0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%T[10]%" IsDateVar="FALSE" _IGNORE="0x0002" _ENABLED="FALSE" _COMMENT="* From Macro Express 3"/>
<DATE/TIME Format="%T[2]%" Flags="\x82" Date="12/30/1899" Day_Offset="-%N[99]%" Month_Offset="-0" Year_Offset="0" Hour_Offset="-0" Minute_Offset="-0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%dtOneDayOld%" IsDateVar="TRUE" _IGNORE="0x0002" _COMMENT="NEW for Macro Express Pro"/>
<COMMENT/>
<REPEAT WITH FOLDER Path="%T[98]%" OnlyFiles="TRUE" Destination="%T[1]%" FullPath="TRUE" ProcSubfolders="FALSE"/>
<VARIABLE SET FROM FILE Filename="%T[1]%" Option="\x00" Date="\x01" Month="%N[2]%" Day="%N[3]%" Year="%N[1]%" Hour="%N[4]%" Minutes="%N[5]%" Seconds="%N[6]%" Flags="\x3F" _ENABLED="FALSE" _COMMENT="* From Macro Express 3"/>
<VARIABLE SET STRING Option="\x00" Destination="%T[31]%" Value="<DT:%T[2]%\\sT:11:2:%N[3]%/%N[2]%/%N[1]%\\s%N[4]%:%N[5]%:%N[6]%>" NoEmbeddedVars="FALSE" _ENABLED="FALSE" _COMMENT="* From Macro Express 3"/>
<RUN MACRO IN VARIABLE Variable="%T[31]%" _ENABLED="FALSE" _COMMENT="* From Macro Express 3"/>
<IF VARIABLE Variable="%T[11]%" Condition="\x02" Value="%T[10]%" IgnoreCase="FALSE" _ENABLED="FALSE" _COMMENT="* From Macro Express 3"/>
<VARIABLE SET FROM FILE Filename="%T[1]%" Option="\x00" Date="\x01" Month="%N[2]%" Day="%N[3]%" Year="%N[1]%" Hour="%N[4]%" Minutes="%N[5]%" Seconds="%N[6]%" Flags="\x40" DateVar="%dtFileDate%" _COMMENT="NEW for Macro Express Pro"/>
<IF VARIABLE Variable="%dtFileDate%" Condition="\x02" Value="%dtOneDayOld%" IgnoreCase="FALSE" _COMMENT="NEW for Macro Express Pro"/>
<IF VARIABLE Variable="%T[3]%" Condition="\x06" Value="Delete" IgnoreCase="TRUE"/>
<WAIT FOR FILE TO BE READY Filename="%T[1]%" Time="0" Indefinite="FALSE" Hours="0" Minutes="0" Seconds="2"/>
<DELETE FILE/FILES Path="%T[1]%" Progress="FALSE" Recurse="FALSE" Permanent="FALSE"/>
<END IF/>
<COMMENT Value="Just make a list of files to be deleted for now"/>
<IF VARIABLE Variable="%T[3]%" Condition="\x06" Value="List" IgnoreCase="TRUE"/>
<VARIABLE MODIFY STRING Option="\x07" Destination="%T[11]%" Variable="%T[1]%" NoEmbeddedVars="FALSE"/>
<VARIABLE MODIFY STRING Option="\x12" Destination="%T[11]%" Filename="%T[4]%\\DisplayTemp.txt" Strip="FALSE" NoEmbeddedVars="FALSE"/>
<END IF/>
<END IF/>
<END REPEAT/>
<PROGRAM LAUNCH Path="%T[4]%\\DisplayTemp.txt" Mode="\x00" Default_Path="FALSE" Wait="1" Get_Console="FALSE"/>
<MACRO RETURN/>

This is what the script should look like (the lines that say "// * From Macro Express 3" should be disabled - with a line drawn through them):

// Delete files older than %N[99]% days from today >
// Demonstrating run Macro in Variable to set comparison Date stamp string from File details
// Uses variables %T[1]%-T4%,%T[11]%, %T[10]%, %T[98]%, %N[99]%, %N[1]%-%N[6]%
Variable Set From Misc:  "Installation Path" into %T[4]%
Multiple Choice Menu: Delete the Files in a Folder?
On Error
  Catch Error: The dialog was cancelled
    Variable Set String %T[3]% to "CANCEL"
  End Catch Error
End Error
Variable Set String %T[98]%: Prompt for a foldername
Variable Set Integer %N[99]% to 1
Variable Set Integer %N[99]%: Prompt
Variable Set String %T[11]% to ""
Variable Set String %T[2]% to "yyyyMMdd"
Variable Modify String: Save %T[11]% to "%T[4]%\DisplayTemp.txt"
Date/Time: Set %T[10]% to an adjusted date/time using "%T[2]%" as the format // * From Macro Express 3
Date/Time: Set %dtOneDayOld% to an adjusted date/time // NEW for Macro Express Pro
 
Repeat with Folder %T[98]%
Variable Set From File date // * From Macro Express 3
Variable Set String %T[31]% to "<DT:%T[2]%\sT:11:2:%N[3]%/%N[2]%/%N[1]%\s%N[4]%:%N[5]%:%N[6]%>" // * From Macro Express 3
Run Macro in Variable: %T[31]% // * From Macro Express 3
If Variable %T[11]% Is Less Than "%T[10]%" // * From Macro Express 3
  Variable Set From File date // NEW for Macro Express Pro
  If Variable %dtFileDate% Is Less Than "%dtOneDayOld%" // NEW for Macro Express Pro
    If Variable %T[3]% Contains "Delete"
      Wait for File to be Ready: %T[1]%
      Delete File/Files: "%T[1]%"
    End If
    // Just make a list of files to be deleted for now
    If Variable %T[3]% Contains "List"
      Variable Modify String %T[11]%: Append Text String Variable (%T[1]%)
      Variable Modify String: Append %T[11]% to text file, "%T[4]%\DisplayTemp.txt"
    End If
  End If
End Repeat
Program Launch: "DisplayTemp.txt" (Normal)
Parameters: 
Macro Return

Link to comment
Share on other sites

  • 7 years later...

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...