[VIEWED 2527
TIMES]
|
SAVE! for ease of future access.
|
|
|
khalisisi
Please log in to subscribe to khalisisi's postings.
Posted on 06-09-09 1:58
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
I need a Windows SysAdmin or the like to help me out with this.... I am trying to automate deletion of old files in a folder (actually several folders .. but I can improvise) and I need a windows batch file to do it. I have googled my ass off without success (I browsed through tons of nonsense all day today...) does anyone have a script that does this... or any pointers...?? please know what you are talking about because I have tried just about everything. This should not be so difficult.. right? go figure! Thanks
|
|
|
|
Yesai
Please log in to subscribe to Yesai's postings.
Posted on 06-09-09 2:23
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Write a VBscript to delete the File and Invoke the Script with Batch file(Invoking a VBScript with Batch file is very easy as well as the Folder deletion using vbscript-Google it)..U can invoke the Script with the Windows Scheduler..
Hope it helps
|
|
|
Yesai
Please log in to subscribe to Yesai's postings.
Posted on 06-09-09 2:39
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Deletes the folder C:\Scripts.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colFolders = objWMIService.ExecQuery _ ("Select * from Win32_Directory where Name = 'c:\\Scripts'") For Each objFolder in colFolders errResults = objFolder.Delete Wscript.Echo errResults Next
In .cmd file cscript scripts.vbs
It should work
|
|
|
khalisisi
Please log in to subscribe to khalisisi's postings.
Posted on 06-09-09 3:18
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Thanks! I just found out that this could also be done using the xxcopy utility.. let me know if anybody needs to know how... I figure it makes life easier for the visual basic retards like myself, but the script you provided looks awesome.. will try it!
|
|
|
khalisisi
Please log in to subscribe to khalisisi's postings.
Posted on 06-09-09 3:19
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
when I said xxcopy utility.. I did not mean that the utility does this by default.. there is a little hack involved... FYI
|
|
|
Khairey
Please log in to subscribe to Khairey's postings.
Posted on 06-10-09 12:24
AM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
I normally use powershell for scripting on windows. Keyword here.. powershell.. explore it, you will love it if you are more inclined to do unix like scripting on windows. The above script will delete the folder I think. To delete files use this WQL instead: Select * from CIM_DataFiles where Drive='C:' and Path='\\somefolder\\' and Extension='log' and LastModified < '01/01/2009 00:00:00' You can easily use some date function and pass on that query.
|
|
|
Khairey
Please log in to subscribe to Khairey's postings.
Posted on 06-10-09 12:38
AM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Also, the WMI object will let you execute the query and methods on remote hosts also. I think for local simple dos command del would do the trick. If you are up to robust script, go for using WMI Objects by vbscript or powershell or even php. If you are still stuck, you may need to google your ass off more ;)
|
|
|
Khairey
Please log in to subscribe to Khairey's postings.
Posted on 06-10-09 3:50
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Dude, here is another I wrote to execute on a local machine. But I would prefer above. ' This script deletes all the files on fileFolder which are 3 days older than now. fileFolder = "C:\Documents and Settings\khairey\Local Settings\Temp" dateToDelete = DateAdd("d",-3,Now()) Dim objFSO Dim objFolder Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.GetFolder(fileFolder) For Each file in objFolder.Files If file.DateCreated < dateToDelete Then objFSO.DeleteFile file, True End If Next Save it as deletefile.vbs run it as c:>cscript deletefile.vbs
|
|