General discussion

Locked

.vbs script to verify copied directories

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

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by StreamLogic In reply to .vbs script to verify cop ...

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

Back to Web Development Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums