Monday, February 28, 2011

Scheduling the task using WSH script

Sometimes you need to do some automated task perform by the system itself, for a specific time period. You can do this by WSH script.
The below code uses to move the file from one folder to another folder at a specific time period


Code
Dim OriginFolder, DestinationFolder, sFile, oFSO, oShell  
 Set oFSO = CreateObject("Scripting.FileSystemObject") 
 Set oShell = CreateObject("Wscript.Shell") 
 OriginFolder = "d:\folder1" 
 DestinationFolder = "d:\folder2" 
 On Error Resume Next  
  
   Call MoveFiles()  
   
 Sub MoveFiles() 
  
     For Each sFile In oFSO.GetFolder(OriginFolder).Files 
       If Not oFSO.FileExists(DestinationFolder & "\" & oFSO.GetFileName(sFile)) Then 
  oFSO.GetFile(sFile).copy DestinationFolder & "\" & oFSO.GetFileName(sFile),True 
  oFSO.deleteFile(OriginFolder & "\" & oFSO.GetFileName(sFile))
     End If 
     Next 
    
 End Sub 


Steps to install the script in Scheduled Task. Browse your .vbs file in Scheduled Task.





Download Code