General discussion

  • Creator
    Topic
  • #2257754

    .vbs script to verify copied directories

    Locked

    by thom0 ·

    Hi. I’m trying to create a script that can copy a whole directory, verify the copy is a match to the original and delete the source only if verification is ok. If verification fails I don’t want anything to happen (maybe delete the created directory or pop up a message box)

    I’ve been using this batch file called newmove.bat at the moment;


    @rem
    numove.bat

    @echo
    off

    if /i “%1″==”” goto nopar1
    if /i “%2″==”” goto nopar2

    :main
    xcopy /y /e /v /i “%1” “%2”
    del /f /s /q “%1”
    rd /s /q “%1%”
    goto exit

    :nopar1
    echo.
    echo ***Source directory parameter missing***
    echo.
    echo Usage: numove [sourcedir] [destinationdir]
    goto exit

    :nopar2
    echo.
    echo ***Destination directory parameter missing***
    echo.
    echo Usage: numove [sourcedir] [destinationdir]
    goto exit

    :exit

    I hate to think what happens if the source is deleted and the copy is corrupted. /gulps

    Anyone have any idea how to proceed?

    Cheers

    Theers

All Comments

  • Author
    Replies
    • #3201128

      Reply To: .vbs script to verify copied directories

      by streamlogic ·

      In reply to .vbs script to verify copied directories

      thom0,

      You can accomplish this by using the FileSystemObject in VBScript (vbs).

      Something like:

      Dim oFSO
      Dim sCurrentFolder
      Dim sNewFolder

      sCurrentFolder = “c:\testfolder”
      sNewFolder = “c:\testfolder2”

      Set oFSO = CreateObject(“Scripting.FileSystemObject”)
      oFSO.CopyFolder sCurrentFolder, sNewFolder

      ‘Verify size to see if everything copied.
      If (oFSO.GetFolder(sCurrentFolder).size = oFSO.GetFolder(sNewFolder).size) Then
      oFSO.DeleteFolder(sCurrentFolder)
      End If

      You can also add better verification other than size if you want. Here is a reference for FileSystemObject:
      http://www.tutorial-web.com/asp/fso/

      Hope this helps,
      Curtis

      Curtis Hughes
      StreamLogic Inc.
      http://www.StreamLogicInc.com

Viewing 0 reply threads