Wednesday, February 9, 2011

Script to Move a file from one Place to another

'Move File
On Error Resume Next
dim objFSO
dim objFile

'specify filename and path for file to move
strFile="c:\file.txt"
'specify target destination
strDest="c:\Neeraj\"

set objFSO=CreateObject("Scripting.FileSystemObject")
'move will fail if file already exists in target destination
objFSO.MoveFile strFile,strDest

if err.number=0 then
       wscript.Echo "Successfully moved " & strFile & " to " & strDest
else
       wscript.Echo "Failed to move " & strFile & " to " & strDest
end if

err.Clear
set objFSO=Nothing

No comments: