[Show all top banners]

khalisisi
Replies to this thread:

More by khalisisi
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 Batch File -- Sys Admins please help
[VIEWED 2527 TIMES]
SAVE! for ease of future access.
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


 


 


 
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

 
Posted on 06-09-09 2:39 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Deleting Folders


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

 
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!


 
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
 
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.
 
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 ;)
 
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



 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 30 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
मन भित्र को पत्रै पत्र!
emergency donation needed
Guess how many vaccines a one year old baby is given
अमेरिकामा बस्ने प्राय जस्तो नेपालीहरु सबै मध्यम बर्गीय अथवा माथि (higher than middle class)
Travelling to Nepal - TPS AP- PASSPORT
ढ्याउ गर्दा दसैँको खसी गनाउच
Morning dharahara
nrn citizenship
जाडो, बा र म……
1974 AD Pinjadako Suga Remixed
Susta Susta Degree Maile REMIXED version
Elderly parents travelling to US (any suggestions besides Special Assistance)?
कल्लाई मुर्ख भन्या ?
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters