Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

SQL Scripts & Samples

Posted Jun 17, 2004

Delete Old Folders

By DatabaseJournal.com Staff



>>Script Language and Platform: MSSQL/VBScript
This VBScript can be used to delete old folders.

'Usage: DeleteOldFolder "\\Servername1\Sharename\Replication\" "3" "\\servername2\log\DeleteOldFolders.log"

'Usage: DeleteOldFolder "d:\MSSQL\BACKUP\Replication\" "2" "C:\mylog.txt"

Author: MAK


'Objective: To Delete folders older than certain # of days.
'Created by: MAK
'Date Written: Jun 4, 2004
'Usage: DeleteOldFolder "\\Servername\d$\MSSQL\BACKUP\Replication\" "2" "C:\mylog.txt"
'Usage: DeleteOldFolder "\\Servername1\Sharename\Replication\" "3" 
	"\\servername2\log\DeleteOldFolders.log"
 
On error resume next
 
if isnull(WScript.Arguments(0))=True or isnull(WScript.Arguments(1))=True 
	or  isnull(WScript.Arguments(2))=True then
msgbox "Usage: DeleteOldFolder" & "'\\Servername1\Sharename\Replication\' '3' 
	'\\servername2\log\DeleteOldFolders.log'"
end if
 
Dim Directory 
Dim Noofdays
Dim FSO
Dim FSO2
Dim LogFile
Dim Folderlist 
Dim folders 
 
Directory =WScript.Arguments(0)
Noofdays=cint(WScript.Arguments(1))
LogFile=WScript.Arguments(2)
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FSO2 = CreateObject("Scripting.FileSystemObject")
Set oFSO = CreateObject("Scripting.FilesyStemObject")
Set ofile = oFSO.createTextFile(LogFile, True)
ofile.writeline "DeleteOldFolders Started"
ofile.writeline now()
 
Set Folderlist = FSO.GetFolder(Directory)
 
Set folders = Folderlist.SubFolders
        For Each d In Folders
'          msgbox d.name 
'          msgbox d.size
'          msgbox d.dateCreated
'          msgbox d.dateLastModified
'          msgbox d.dateLastAccessed
tempdirectory = Directory & d.name 
 
'msgbox Noofdays 
'msgbox datediff("d",d.dateCreated,now()) 
If  datediff("d",d.dateCreated,now()) > Noofdays Then
       FSO2.DeleteFolder(tempdirectory )
ofile.writeline cstr(now()) & "    " & tempdirectory & " Delete Started"
 
if err.number <>0 then
ofile.writeline cstr(now()) & "    " & Err.description 
err.clear
else
ofile.writeline cstr(now()) & "    " & tempdirectory & " has been deleted"
err.clear
end if
'       msgbox tempdirectory & " has been deleted"
       End If
Next
'msgbox "Done"
ofile.writeline "DeleteOldFolders Completed"
ofile.writeline now()


Disclaimer: We hope that the information on these script pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided "as -is", without any warranty, whether express or implied, of its accuracy, completeness, or fitness for a particular purpose... Disclaimer Continued


Back to Database Journal Home



SQL Scripts & Samples Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
SQL Scripts & Samples Forum
Topic By Replies Updated
sql help!! add 1 August 22nd, 11:58 AM
How To Combine These 2 Queries into 1 Query ? tarek_land 1 June 7th, 08:37 AM
solving query svibuk 1 February 3rd, 06:08 AM
converting from a character string to uniqueidentifier saturnius 4 January 4th, 05:56 AM


















Thanks for your registration, follow us on our social networks to keep up-to-date