Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have created a NET USE batch file that will xcopy an entire directory to a server for updating purposes, but I am having a problem with my IF EXISTS and IF NOT EXIST statements.
After I use NET USE and assign a drive letter (R:) to the share, I want te batch program to verify the connection. If it exists then the program will copy the directory over to the server and output a file in the Update folder. If the NET USE failed and the connection does not exist, then the program should GOTO the :ABORT section, output a file in hte Error folder and exit the program.
Well, the program works fine when I test each section. But when I put them all together, the IF [NOT] EXIST statements are completly over looked and whatever section of the program I place after them completes next.
Any help at all would be greatly appreciated.Thank you in advance,
Rice BlackHere is my batch file:
@ECHO OFF
ECHO This program will update all of the
ECHO Collectors Files on the server Sa48.:STEP1
ECHO.
ECHO.
ECHO Step 1 - Verifing the connection to the
ECHO server and it's directory structure.NET USE R: \\Sa48\VOL1\AUDIT\COLLECTR\WINCOL count8 /YES
GOTO STEP2:STEP2
IF EXIST R: GOTO STEP3
IF NOT EXIST R: GOTO ABORT:ABORT
ECHO.
ECHO Either a connection to the server cannot be made
ECHO Or the directory structure is not correct.
ECHO Please double check the connection to the server
ECHO and it's directory structure.
ECHO Aborting copy procedure.
ECHO Connection Error - Files were not copied > C:\Rice\Collector_Files\Export_Errors\Sa48_Error.txt
pause
GOTO EXIT:STEP3
ECHO Step 1 Completed!
ECHO Ready to update the Collecor Files on Sa48.
XCOPY C:\Rice\Collector_Files\Test\*.* R: /s/e/v/i/r/y
GOTO STEP4:STEP4
ECHO The Sa48 server directory has been updated. > C:\Rice\Collector_Files\Updated_Srvrs\Sa48_Updated.txt
GOTO STEP5:STEP5
NET USE R: /Delete /Yes:EXIT

It's very simple really... If can't check for the existance of a directory, it has to check for a file within the directory... Luckily you can plug in the DOS constant (it's also a virtual device) NUL with the same results...
I.E.If exist c:\nul then goto blah
The above command will check for the existance of the c drive. All you would need to do to get your batch working is change the plain old r: to r:\nul .
Hope that helps,
-Michael

GOTO STEP2
:STEP2
IF EXIST R: GOTO STEP3
GOTO ABORTMight be a little tighter.
Or if not exist R: goto abort
then
goto step3

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |