How check share UNC
Moderator: DosItHelp
How check share UNC
Hello everyone,
I'm looking for a very simple script that check if UNC share as "\\server\abc" is available before copy some file into that.
I got error after copy file, but it would be useful to know before if a share is down or user has no permission to copy file.
Best Regards
I'm looking for a very simple script that check if UNC share as "\\server\abc" is available before copy some file into that.
I got error after copy file, but it would be useful to know before if a share is down or user has no permission to copy file.
Best Regards
Re: How check share UNC
Well to see if the share is up and running you could just do an IF EXIST.
Not sure about testing for permissions. I guess I would just try and copy the batch file itself to the share and check the errorlevel.
Code: Select all
if EXIST "\\Server\Share\Folder" echo exists
Not sure about testing for permissions. I guess I would just try and copy the batch file itself to the share and check the errorlevel.
Re: How check share UNC
I check this script
if exist errorlevel=0
if NOT exist errorlevel=0
if NOT authorized errorlevel=0
That's the point !
Code: Select all
if EXIST "\\Server\Share\Folder" echo exists
if exist errorlevel=0
if NOT exist errorlevel=0
if NOT authorized errorlevel=0
That's the point !
Re: How check share UNC
Note the trailing slash - it defines a folder.
Check it yourself to see what happens if you don't have access.
Code: Select all
if EXIST "\\Server\Share\Folder\" (
copy file
) else (
echo unavailable
)
Check it yourself to see what happens if you don't have access.
Re: How check share UNC
darioit wrote:
if exist errorlevel=0
if NOT exist errorlevel=0
if NOT authorized errorlevel=0
None of those are properly formatted commands.
Re: How check share UNC
Foxidrive makes a good point about the trailing slash. That way it matches against a folder or share name and not a file.
It does work. I normally don't post code unless I tested it first.
It does work. I normally don't post code unless I tested it first.
Code: Select all
H:\>IF EXIST "\\Server\Share\TEMP\" echo the Folder exists
the Folder exists
Re: How check share UNC
Squashman wrote:darioit wrote:
if exist errorlevel=0
if NOT exist errorlevel=0
if NOT authorized errorlevel=0
None of those are properly formatted commands.
sorry this is not a command but the result of command
This is the right script:
Code: Select all
if exist "\\Server\Share\Folder" echo exists
echo %errorlevel%
in all case tested %errorlevel% is always 0
regards
Re: How check share UNC
darioit wrote:Squashman wrote:darioit wrote:
if exist errorlevel=0
if NOT exist errorlevel=0
if NOT authorized errorlevel=0
None of those are properly formatted commands.
sorry this is not a command but the result of command
This is the right script:Code: Select all
if exist "\\Server\Share\Folder" echo exists
echo %errorlevel%
in all case tested %errorlevel% is always 0
regards
Of course the ERRORLEVEL will be zero because the IF command completed successfully. It didn't error out.
Code: Select all
H:\> if 1==1 echo equal
equal
H:\>echo %errorlevel%
0
H:\> if 1==0 echo equal
H:\>echo %errorlevel%
0
Either use the IF ELSE code Foxidrive gave you to execute another command when the condition is true or set a flag with another variable.
Code: Select all
if exist "\\Server\Share\Folder" set SHAREFLAG=Y