Computing.Net > Forums > Disk Operating System > IF EXIST & IF NOT EXIST PROBLEMS

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

IF EXIST & IF NOT EXIST PROBLEMS

Reply to Message Icon

Name: Rice Black
Date: October 10, 2001 at 08:55:39 Pacific
Comment:

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 Black

Here 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



Sponsored Link
Ads by Google

Response Number 1
Name: Michael
Date: October 10, 2001 at 10:33:11 Pacific
Reply:

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


0

Response Number 2
Name: World library
Date: October 10, 2001 at 14:37:52 Pacific
Reply:


GOTO STEP2
:STEP2
IF EXIST R: GOTO STEP3
GOTO ABORT

Might be a little tighter.

Or if not exist R: goto abort
then
goto step3


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: IF EXIST & IF NOT EXIST PROBLEMS

bath file if not statment problem www.computing.net/answers/dos/bath-file-if-not-statment-problem/6470.html

Search for right file path if exist www.computing.net/answers/dos/search-for-right-file-path-if-exist/16660.html

If exist doesn't work www.computing.net/answers/dos/if-exist-doesnt-work/16677.html