DOS Command for Folder Comparison

I'm currently using a batch script to run XCOPY to move contents from a source directory to a target directory.  These contents that I'm moving also contain sub folders.   These contents are not static paths and change with whatever folder (contents) I pass into this batch script.  The script runs perfectly fine except today I noticed an error where XCOPY seemed to fail because there was some sort of network glitch between the target directory (another server) and me.  

So what I need to do is put some sort of test in place inside this batch script file that can compare the source directory from the target directory to let me know if the XCOPY failed.  

So here's the problem, I need to find a DOS command or something that can be called from the batch script program that can determine if the source directory is the same as the target directory and if not alert the user that there was a problem with XCOPY after the command runs.  

I have been looking in the Resource Disk for Windows NT and XP but I can't find anything.   Others out there must have run into this problem in the past and needed some sort of catch/test that would determine if XCOPY worked or not.   Can anyone guide me in the right direction of such a test?
Who is Participating?
Lee W, MVPTechnology and Business Process AdvisorCommented:
If you want it to stop, just use:

IF "%errorlevel%" NEQ 0 GOTO EOF

With a copy of your code, we could modify it and make it work for you.
Lee W, MVPTechnology and Business Process AdvisorCommented:
Why not just log the transfer and create an error log?

For example, append the following to your XCOPY line:

>> copy.log 2>>&1 copyerr.log
Lee W, MVPTechnology and Business Process AdvisorCommented:
Otherwise, you can also do a DIR on the source directory and a DIR on the Target directory and redirect output to a text file.  Then run COMP to compare the two files.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

All you need is the right tool to copy your files with. copy and xcopy are fine if you only copy a few files. If you copy larger amounts of data, especially over a network connection, do yourself a favor and use robocopy ("robust copy") from the Resource Kit. You get a log file, it will by default copy only files that aren't already in the target, and it will retry if it fails.
Have a look at the file robocopy.doc in the installation directory for a complete explanation.
The available switches look a bit frightening at the beginning, but you won't need most of them. Pay attention to the /w (wait) and /r (retry) settings and set them to useful values.

Windows Server 2003 Resource Kit Tools
Use WinDiff to compare directories after the robocopy is finished.  It will compare the complete folder structure and files and report if there are any differences.  You can find WinDiff in the 2003 support tools.  
healthshareAuthor Commented:
The thing is I run a batch script that will copy whatever directory I give it in the parameters and it pastes it to the target directory.   Then I have another batch script that will make multiple calls to that other batch script to copy and paste many many directories to whatever target directory I pick.   so basically I could have a program running for hours just copying and pasting directories and if it fails I want it to either give me the reason why it's failing and stop the rest of the process or after the xcopy is done for that one command to then have another script test whether the 2 directories are either the same or different (if they are different, then they should fail).  

So basically here's what I have, a main script file that will take these parameters:

CopyCustomer [SourceDirectory] [Customer] [TargetLocation]

Then I have another batch script that will make multiple calls like this:

CALL CopyCustomer \\source1\     Customer1    \\target2\...\
CALL CopyCustomer \\source2\     Customer2    \\target3\...\
CALL CopyCustomer \\source1\     Customer3    \\target2\...\
CALL CopyCustomer \\source2\     Customer4    \\target1\...\
CALL CopyCustomer \\source1\     Customer5    \\target2\...\
CALL CopyCustomer \\source1\     Customer6    \\target4\...\
CALL CopyCustomer \\source2\     Customer7    \\target1\...\

So I don't want the process to continue the whole way through if there was an error and the source directory and target directory are different.  That's why I was thinking of some sort of error catching that could compare the folders after it was done and tell me if there was a problem and if there was stop the rest of the process.

But I did manage to find something else I wasn't aware of, XCOPY has exit codes that allow you to catch any error codes that may come out of the copy process and then do something with a IF statement which you could then exit the program via an error in the copy process.   This may be my solution.  I'm still testing it out.  I will follow up if it is.   Thanks for all the feedback up to this point.
healthshareAuthor Commented:
nope.  I'm all set.  I think I just answered my own question by using the XCOPY's exitcode.    

I was really hoping for some sort of DOS command that I could call within my script that could compare two directories and tell me if they are the same or not and give me an exitcode or boolean in return.  But it seems as if that sort of command doesn't exist in the DOS world.   I thought it would.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.