You can use schedule this script to move files on a server daily from on location to another.
Simple copy the script to a text file using notepad.exe and save as .vbs or download here.
' Use at your own risk
' Customize as you wish
Const cFROM = "E:\Source"
Const cDEST_ROOT = "E:\Destination"
Const cDAYS_OLD = 5
Const cFROM_EMAIL = "yourname@yourdomain.com"
Const cTO_EMAIL = "yourname@yourdomain.com"
Const cCC_EMAIL = "yourname@yourdomain.com"
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check directory existence
If Not objFSO.FolderExists(cFROM) Then
strMessage = "Either soure or destination folder does not exists." & vbCrLf & _
"Source Folder:" & vbTab & cFROM & vbCrLf & _
"Please make sure that source path is correct and exists before running the " & _
"script again." & vbCrLf & vbCrLf & _
"Thanks."
Call SendEmail("Error:Move Script", strMessage)
Call Destroy()
WScript.Quit
End If
strDest = cDEST_ROOT & Month(Now) & "-" & Year(Now) & "\"
' Create destination directory if doesn not exists
If Not objFSO.FolderExists(strDest) Then
objFSO.CreateFolder(strDest)
End If
Dim objGFO
Set objGFO = objFSO.GetFolder(cFROM)
Dim objGFI
Set objGFI = objGFO.Files
strMessage = "This summary report contains the total number of files that were moved to " & _
strDest & " from " & cFROM & vbCrLf & vbCrLf
intGFI = 0
Dim strGFI
For Each strGFI in objGFI
If DateDiff("d", strGFI.DateLastModified, Date) >= cDAYS_OLD Then
strFileName = strGFI.Name
If objFSO.FileExists(strDest & strFileName) Then
objFSO.DeleteFile strDest & strFileName, True
End If
objFSO.MoveFile cFROM & strFileName, strDest
intGFI = intGFI + 1
'strMessage = strMessage & intGFI & ". " & cFROM & strFileName & " was moved successfully." & vbCrLf
'Exit For
End If
Next
strMessage = strMessage & vbCrLf & "Successfully archived " & intGFI & " file(s) to " & strDest & vbCrLf
Call SendEmail("Move Script Daily Summary Report", strMessage)
Call Destroy()
Sub SendEmail(strSubject, strMessage)
Dim strEmailBody
Dim objEmail
Set objEmail = CreateObject("CDO.Message")
'Email fields
objEmail.From = cFROM_EMAIL
objEmail.To = cTO_EMAIL
objEmail.Cc = cCC_EMAIL
objEmail.Subject = strSubject & vbTab & "***Timestamp*** " & Now()
objEmail.Textbody = strMessage
'Smtp configurations
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtp.usadata.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub
Sub Destroy()
Set objGFI = Nothing
Set objGFO = Nothing
Set objFSO = Nothing
End Sub
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2010
(56)
-
►
March
(10)
- MX Toolbox FREE Blacklist (RBL) Monitoring
- VMware HA Schematics
- VMware HA Quick Guide
- FREE Online Tools for E-mail Administrators
- Change boot order in Windows 7
- Vmware Site Survey
- How to remove Storage Groups in EMC Navisphere?
- MPIO & Multihoming Windows Server to iSCSI SAN wit...
- PowerCLI Script for Snapshot Reporting (vSphere)
- How to Restore Mailbox using Recovery Storage Grou...
-
►
February
(10)
- Enable RPC/HTTP (Outlook Anywhere) in Exchange 200...
- Moving Mailboxes - Exchange 2007 SP1
- How to search items in a list against another list...
- How to remove empty rows in Excel?
- SSL Traffic and Microsoft ISA 2006 Server
- Use CLI to add new port groups in VMware ESX 3.5 o...
- Vmkernel Default Gateway in ESX
- Use man UNIX command to see all esxcfg commands in...
- Display routing table on ESX / Linux
- Software iSCSI Rescan HBAs Commands in vSphere (ES...
-
▼
January
(30)
- VBScript to Move Files
- Restart Windows services on remote computers
- Batch File To Turn Power On and Off Monitor or LCD...
- Get notify about TrendMicro OfficeScan anti-virus ...
- Update timestamp on multiple files in multiple fol...
- A tool to archive old IIS logs.
- Replace file extensions for multiple files in a fo...
- Creational Design Patterns Quick Reference
- Change name for multiple files in a folder in a ba...
- A Quick Reference & Tutorial for ASP.NET
- How to calculate SQL table sizes?
- A Quick Reference for T-SQL
- A Quick C# Programming Language Reference
- Nslookup & Service Records ( SRV Records )
- How to locate authorized and non-authorized (rouge...
- Get the MAC address of remote desktop or server in...
- Windows 2008 Disk Resize Fix - Error 0xc0000225
- How to change SRV records priorities and weight fo...
- MTU Maximums (Jumbo Frames) for ESX 4.0, Windows 2...
- Windows 2008 License Activation Quick Overview - K...
- Exchange 2007 OWA Address Book Search Bug
- iSCSI SAN & Multihoming
- How to reset system folders in Outlook?
- A Quick Guide to Windows Terminal Server Setup
- LAN Switch Build Guideline Document Checklist for ...
- Windows 2008 RADIUS Server - NPS/NPAS Checklist & ...
- Windows 2008 NFS & ESX 4.0 - Best Practices & Quic...
- Windows 2008 Failover Cluster & iSCSI - Quick Fact...
- Server Build Document & Guidelines - Windows & ESX...
- Test Plan Template
-
►
March
(10)
0 comments:
Post a Comment