Batch script to test if a folder exists fails when checking a UNC path

I've written a small batch file to help us with a server migration to remap user directories using GPO.

However in the batch file I'm having a syntax problem that appears right but it's still failing. Here is what I have so far below.

If exist "\\server\UserData\%username%"     
GOTO :UNMAP    
ELSE    
NET USE H: \\newserver\UserData\%USERNAME%    
:UNMAP    
NET USE H: /DELETE /Y    
NET USE H: \\newserver\UserData\%USERNAME%

Now when I run it I get the following:

The syntax of the command is incorrect.
C:\>if exist "\\server\UserData\userfolder"

Any idea how to resolve this or what I am doing wrong?


goto :unmap should be on the same line as the if

even better, simplify the whole thing like this:

If exist "\\server\UserData\%username%\." NET USE H: /DELETE /Y
NET USE H: "\\newserver\UserData\%USERNAME%"