pucko73
asked on
Delete files older than a specified date from a vbscript
Hello.
I like to find all files Starting with MyIni
in the path that I can find in "%USERPROFILE%" but only
if they are older than a specified date. (Say first of january 2014 for example)
(IE se the code below... But I need to do that only for files older than a specified date.)
Can someone help me?
Set objShell = CreateObject("Wscript.Shel l")
strUsrProfile = objShell.ExpandEnvironment Strings("% USERPROFIL E%")
Dim fso
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
fso.DeleteFile (strUsrProfile&"\WINDOWS\M yIni*")
I like to find all files Starting with MyIni
in the path that I can find in "%USERPROFILE%" but only
if they are older than a specified date. (Say first of january 2014 for example)
(IE se the code below... But I need to do that only for files older than a specified date.)
Can someone help me?
Set objShell = CreateObject("Wscript.Shel
strUsrProfile = objShell.ExpandEnvironment
Dim fso
Set fso = CreateObject("Scripting.Fi
fso.DeleteFile (strUsrProfile&"\WINDOWS\M
When you write "older than a specified date", do you mean the files' modified dates are less or equal to a specified date or greater than a specified date?
ASKER
I mean files that was created or modified Before a date I specify
If you're already using FSO, then you will need to iterate all the files in the folder and inspect both the name and the modified date before you delete it.
Here is a thread dealing with a similar issue https://www.experts-exchange.com/questions/28408429/VBScript-to-find-files-in-a-folder-and-all-subfolders-older-than-XX-days-and-delete-them.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Inside the FOR EACH OBJFILE loop, you can just add a check of the file name to match your needs.
~bp
~bp
Actually I added the If objFile.name = "*.log" Then ;)
ASKER
Ok. all the sugested things abowe are doing almost the same as I found searching the net Before I posted here. They are using a variable to find files older than nDays.
I want to find files older than for example 2014-01-01
(ie a specified date)
And that is what I don't know how to get in there....
I want to find files older than for example 2014-01-01
(ie a specified date)
And that is what I don't know how to get in there....
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Either of the last two post will get you there, you can just calculate the number of days from your cutoff date to today and then run the script using that number of days. Or you can change the script slightly to take in a cutoff date rather than a number of days. If you want help working in that change let me know, happy to help.
~bp
~bp
ASKER
Thanks!