Link to home
Start Free TrialLog in
Avatar of healthshare
healthshare

asked on

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?
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

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
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.
SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of healthshare
healthshare

ASKER

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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.