Computer Hope

Microsoft => Microsoft DOS => Topic started by: metal_man77 on March 29, 2017, 10:18:01 AM

Title: net use not going to EOF
Post by: metal_man77 on March 29, 2017, 10:18:01 AM
in an simple "IF" statement, I want, after the text, for it to GOTO :EOF.
This doesn't happens. it simply says : command completed successfully.

Here's the code
Code: (batch) [Select]
@echo off
if exist s:\1.txt (GOTO :exit
) else (
GOTO :net_use)
:net_use
net use s: \\que-mdt-01\fna_mdt\Logs
echo Do Not Delete >>s:\1.txt
GOTO :EOF
:exit
echo Path already exist. Exiting.
pause
exit
:EOF
pause
exit
Title: Re: net use not going to EOF
Post by: Salmon Trout on March 29, 2017, 11:47:10 AM
Edited the if ... else block. Don't put stuff after the first or before the last parentheses. The ) else ( must all be on one line which you did right.

Code: [Select]
@echo off
if exist s:\1.txt (
GOTO :exit
) else (
GOTO :net_use
)
:net_use
net use s: \\que-mdt-01\fna_mdt\Logs
echo Do Not Delete >>s:\1.txt
GOTO :EOF
:exit
echo Path already exist. Exiting.
pause
exit
:EOF
pause
exit

Or you can do this

Code: [Select]
@echo off
if exist s:\1.txt (GOTO :exit) else (GOTO :net_use)
:net_use
net use s: \\que-mdt-01\fna_mdt\Logs
echo Do Not Delete >>s:\1.txt
GOTO :EOF
:exit
echo Path already exist. Exiting.
pause
exit
:EOF
pause
exit
Title: Re: net use not going to EOF
Post by: Salmon Trout on March 29, 2017, 11:56:12 AM
You don't need any labels or gotos, you can just do this

Code: [Select]
@echo off
if exist s:\1.txt (
echo Path already exist. Exiting.
) else (
net use s: \\que-mdt-01\fna_mdt\Logs
echo Do Not Delete >>s:\1.txt
)
pause