Help with error trapping in a script
Posted on 2004-09-18
I'm moving some 1600 files from one server to another. The destination server has folder names that match the source file name. The files are word documents i want stuffed into the matching folder name on the destination server. It would be nice also if the directory don't exist on the destination to create it and then stuff the file. I think the below script will work if you could trap the "file already exist" error. If the file already exist on the destination server i would just like to skip it and go to the next file and try to move it. Hope this makes sense. Below is the script i am working with at this time. If you have a better way please show me.
' Moves files from one directory to another directory where the destination directory is
' named the same as the filename of the file. Example:
' Source Directory ==> c:\temp
' Source Filename ==> abc123.doc
' Destination Directory ==> abc123
' Destination Filename ==> abc123.doc
' This script assumes that the destination directory already exists.
intCount = 0
strSourcePath = "\\jaxnt51\proceng\pms\pm\"
strDestinationPath = "\\jaxnt54\plant\machines\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strSourcePath)
Set colFiles = objFolder.Files
For Each objFile in colFiles
intCount = intCount + 1
strFileName = objFile.Name
DirectoryArray = Split(strFileName, ".", -1, 1)
objFSO.MoveFile strSourcePath & strFilename, strDestinationPath & DirectoryArray(0) & "\" & strFileName
Wscript.Echo "File moves completed. " & intCount & " files moved."
' End of MoveDataFiles.VBS