Delete only files over 1 day old

(imported topic written by DotA)

I’m trying to delete all files named “test_.” that were not created on the current day (are over 1 day old) in all profiles under C:\Users or C:\Documents and settings.

So far my action script looks like this:

//Delete all files starting with "test_" from all profiles under C:\Users
if {name of operating system is "Win7"}
waithidden cmd.exe /c cd C:\Users && del /s /F /Q test_*.*
endif
//Delete all files starting with "test_" from all profiles under C:\Documents and settings
if {name of operating system is "WinXP"}
waithidden cmd.exe /c cd C:\Documents and Settings && del /s /F /Q test_*.*
endif

The above will delete all files starting with test_ in all profiles, now they are asking for only the deletion of files not from the current day. Any suggestions on how to add this in?

(imported comment written by JasonWalker)

I don’t have exactly the same file structure as you, but these examples should help you get started:

q: (pathnames of it, modification time of it) of files whose (now - modification time of it < 1 * day) of folder “c:\windows\temp”

A: c:\windows\temp\chrome_installer.log, ( Sat, 13 Sep 2014 04:34:01 -0500 )

A: c:\windows\temp\MpCmdRun.log, ( Sat, 13 Sep 2014 04:39:43 -0500 )

A: c:\windows\temp\MpSigStub.log, ( Fri, 12 Sep 2014 15:57:50 -0500 )

A: c:\windows\temp\ScheduledHeartbeat.log, ( Sat, 13 Sep 2014 07:06:56 -0500 )

T: 2.500 ms

You can build an Appendfile by concatenating the results with the CR/LF characters “%0d%0a”…

delete __appendfile

appendfile {concatenation “%0d%0a” of (“del /q %22” & it & “%22”) of (pathnames of it) of files whose (now - modification time of it < 1 * day) of folder “c:\windows\temp”}

delete “delete_old_files.cmd”

move __appendfile delete_old_files.cmd

waithidden cmd /c delete_old_files.cmd


Also, in Win7/Win8 there’s a registry key to tell you where the Profiles are. Check whether this is also available on XP and it might save you a few more statements / duplications:

q: expand environment string of (value “ProfilesDirectory” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList” of native registry as string)

A: C:\Users

If that doesn’t work, you could put your hardcoded values right in the Relevance as well…as I said I don’t have your file structures but see if either of these gets what you’re looking for…

q: concatenation “%0d%0f” of (“del /q %22” & it & “%22”) of (pathnames of it) of files whose (name of it starts with “test_” and now - modification time of it < 1 * day) of descendant folders of folder (if name of operating system = “Win7” then “c:\users” else “c:\documents and settings”)

Now, the following gives me an error, I think because some of the folder names under Users can’t be evaluated by BigFix (folder lengths or directory junctions may be confusing it), but if you can avoid scanning all subdirectories and limit the search to certain paths like “Documents” or “Desktop” you may get some mileage out of

q: concatenation “%0d%0f” of (“del /q %22” & it & “%22”) of (pathnames of it) of files whose (name of it starts with “test_” and now - modification time of it < 1 * day) of descendant folders of folder ((expand environment string of (value “ProfilesDirectory” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList” of native registry as string)))

E: The expression could not be evaluated: class IllegalFileName

(imported comment written by JasonWalker)

On that last point…check out

q: pathnames of folders (“Documents”;“Desktop”) of folders of folder ((expand environment string of (value “ProfilesDirectory” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList” of native registry as string)))

A: C:\Users\All Users\Documents

A: C:\Users\All Users\Desktop

A: C:\Users\Default\Documents

A: C:\Users\Default\Desktop

A: C:\Users\Holden\Documents

A: C:\Users\Holden\Desktop

A: C:\Users\Jason\Documents

A: C:\Users\Jason\Desktop

A: C:\Users\Public\Documents

A: C:\Users\Public\Desktop

T: 1.300 ms

I: plural string