Dos if command to do a check .

J

Joe M

How do I create a Dos batch file that checks for computer shares eg.
\\Computer\Data1 and \\Computer\Data2 folder. At any time only one of the
two shares is present. What I need is a batch file that checks for the
present shares.

If exist \\Computer\Data1
:begin
copy .....
:end
else
:begin
copy ...... \\Computer\Data2
:end

Does this do the check???
 
M

Michael Bednarek

How do I create a Dos batch file that checks for computer shares eg.

With any text editor (SCNR); and there is no DOS in NT.
\\Computer\Data1 and \\Computer\Data2 folder. At any time only one of the
two shares is present. What I need is a batch file that checks for the
present shares.

If exist \\Computer\Data1
:begin
copy .....
:end
else
:begin
copy ...... \\Computer\Data2
:end

Does this do the check???

Why do you ask? Does the code you quoted not work under CMD.EXE?

As I understand the output of
IF /?
or
HH %windir%\Help\ntcmds.chm::/if.htm
it should, and rudimentary testing confirms that.

In the general case, your logic is flawed: the mere absence of one
network share doesn't guarantee the presence of another.
 
D

David Trimboli

Joe M said:
How do I create a Dos batch file that checks for computer shares eg.
\\Computer\Data1 and \\Computer\Data2 folder. At any time only one of the
two shares is present. What I need is a batch file that checks for the
present shares.

If exist \\Computer\Data1
:begin
copy .....
:end
else
:begin
copy ...... \\Computer\Data2
:end

Does this do the check???

You didn't specify that either Data1 or Data2 MUST exist (could neither
exist?), but assuming that one must exist:


if exist \\Computer\Data1 (
REM Put your commands
REM for working with the
REM Data1 share on these lines.
) else (
REM Put your commands
REM for working with the
REM Data2 share on these lines.
)


SuStel
Stardate 4349.7
 
M

Matthias Tacke

M said:
How do I create a Dos batch file that checks for computer shares eg.
\\Computer\Data1 and \\Computer\Data2 folder. At any time only one of the
two shares is present. What I need is a batch file that checks for the
present shares.

If exist \\Computer\Data1
:begin
copy .....
:end
else
:begin
copy ...... \\Computer\Data2
:end

Does this do the check???
Would be nice if you prove your capabilities in reading before posting.
The question from Larry is quite the same and answered only some threads
back.
 
D

David Trimboli

Would be nice if you prove your capabilities in reading before posting.
The question from Larry is quite the same and answered only some threads
back.


What are you talking about? Larry asked about "Placing two netbios name on
the same line" and "For command ?" Neither of these answer Joe's question,
which was how to check for the existence of network shares.

David
Stardate 4349.9
 
M

Matthias Tacke

David Trimboli said:
What are you talking about? Larry asked about "Placing two netbios
name on the same line" and "For command ?" Neither of these answer
Joe's question, which was how to check for the existence of network
shares.
Yes, maybe my tone was a bit harsh, but you shouldn't stop reading at
the subject. There is a certain level of abstraction neccessary in
scripting / programming.

As Michael already mentioned the else clause without an additional
if is a bit dangerous. If you insert this and can't find a similarity to
my posting in Larry's thread .... the key word is abstraction.

And for can be very helpful, see this fragment:

@echo off & setlocal
set pc=\\computer
set share=data
for /F "tokens=1" %%A in ('net view %pc% ^|findstr /I /B "%share%" ') do (
echo found share %pc%\%%A
)
 
M

Matthias Tacke

M said:
How do I create a Dos batch file that checks for computer shares eg.
\\Computer\Data1 and \\Computer\Data2 folder. At any time only one of the
two shares is present. What I need is a batch file that checks for the
present shares.

If exist \\Computer\Data1
:begin
copy .....
:end
else
:begin
copy ...... \\Computer\Data2
:end

Does this do the check???
Hello Joe,
shortened from my answer to David IMO this line copies only to the first
existant share. (Provided there are no shares data3..etc )

for /F %%A in ('net view \\computer ^|findstr /I /B "data" ') do copy x %pc%\%%A

HTH
 
J

Joe M

Thanks folks, yes there will always only be either exist for the computer.
Because it's two EXTERNAL Backup USB DRIVE and only one is connected at any
time. So if Data1 exist then the code would copy to Data1. Or if Data2 exist
the code would only copy to Data2 and skipped Data1. I am very good at Dos
batch that's why I asked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top