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.
Moving files older than 30 days to a new folder
Moderators: JRL, Dorian (MJT support)
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...
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...