Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to write a batch file to

  • Access \sharelocation\folder\file
  • Compare that file to c:\folder\file
  • If the files are the same, run the local file.
  • If the files are different, replace the local file and run the new local file.

I'm stuck on the first part. Is there a good way to do this?

Maybe I can use net to map the share to a fixed letter if not already mapped then use fc /b?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Something along these lines:

The whole script should be:

net use x: \\share\location
fc c:\folder\file x:\folder\file
if errorlevel 1 goto filesDiffer
:noDifferences
echo Do something when there are no differences
goto theEnd

:filesDiffer
echo Do something when there are differences

:theEnd
net use x: \\share\location /delete

Note you would have issues if x: is already mapped on the target machine. Use fc /b for binary comparison.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.