Moving files older than 30 days to a new folder

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
gbarnes
Newbie
Posts: 1
Joined: Mon Feb 06, 2006 11:25 am

Moving files older than 30 days to a new folder

Post by gbarnes » Mon Feb 06, 2006 11:32 am

Hi,

Today is the first time I am using VBS and I need to create a script that moves files older than 30 days to a new directory. I have found some scripts for deleting files but I can't understand the code so I can't change it. Does anyone have any scripts with comments that can help me? The one I am trying to work with is:-

strDate = "20060101000000.000000+000"

strComputer = "."
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * From CIM_DataFile Where CreationDate < '" & strDate & "'")
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
strDate = "20060101000000.000000+000"

strComputer = "."
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * From CIM_DataFile Where CreationDate < '" & strDate & "'")
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next

I have managed to set the date to Jan 1st but thats about it. The rest is pretty much nonsense to me.

User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Post by pgriffin » Mon Feb 06, 2006 2:37 pm

Looks like to grabbed the code from a script without the MacroScheduler lines included, so it doesn't make sense to me either....

I would suggest something simple.

This is not syntactically correct, but these are the commands I would look into using.

GetFileList> this will create a list of files you might want to delete
FileDate> this will give you the date of an individual file from the 'GetFileList' list.....
GetDate> this will give you today's date.

Now all you have to do is compare the dates from FileDate to GetDate and have the script delete the file if the difference is >30.

No VBS required...

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts