Help with this code?

February 14, 2011 at 12:34:44
Specs: Windows 7, Intell core2quad 2.4 / 4gb
Ok ive got the following code.

what i need is help with the if exist "..." and also maybe a bit of help with the labels?
I know this isnt the best format of the code and there are probably much easier ways of doing it but i dont know "delims, tokens" or well any of that funny stuff but I am trying to get to know it.

:REMEMBERED
pushd ..
goto MAKEDIR
:MAKEDIR
cd\
mkdir User
goto REMEMBER
:REMEMBER
popd
goto COPY
:COPY
copy toets.doc C:\User\
goto SEARCH 1
:SEARCH 1
if exist "C:\Program Files\VideoLAN\VLC\vlc.exe"
goto COPY1
:SEARCH2
if exist "C:\Program Files\Winamp\winamp.exe"
goto COPY2
:SEARCH3
if exist "C:\Program Files\Windows Media Player\wmplayer.exe"
goto COPY3
:COPY1
cd\
cd\User\
copy toets.doc toets1.doc
ren toets.doc toets.flv
ren toets1.doc toets.doc
goto OPEN1
:COPY2
cd\
cd\User\
copy toets.doc toets1.doc
ren toets.doc toets.mp3
ren toets1.doc toets.doc
goto OPEN2
:COPY3
cd\
cd\User
copy toets.doc toets1.doc
ren toets.doc toets.wma
ren toets1.doc toets.doc
goto OPEN3
:OPEN1
start toets.flv
start toets.doc
pause
:OPEN2
start toets.mp3
start toets.doc
pause
:OPEN3
start toets.wma
start toets.doc
pause

any help would be appreciated


See More: Help with this code?

Report •

#1
February 14, 2011 at 13:07:12
Replace

if exist "C:\Program Files\VideoLAN\VLC\vlc.exe"
goto COPY1

with

if exist "C:\Program Files\VideoLAN\VLC\vlc.exe" goto COPY1

and the same for any if exist statement or code

if exist "C:\Program Files\VideoLAN\VLC\vlc.exe" (
  goto COPY1
)

And a label is terminated by its first space, the remainder is interpreted as comment so

:SEARCH 1 must become SEARCH_1


Report •

#2
February 14, 2011 at 13:45:54
Thank you very much.

Although i dont know much about CMD I still tried... and failed lol but you helped me a lot.


Report •

#3
February 14, 2011 at 15:34:54
but i dont know "delims, tokens" or well any of that funny stuff

Read this How-To on tokens and delims, and also this one written by Judago. The latter is a little more in-depth than the one I wrote.

Can I put a question here?


Report •

Related Solutions

#4
February 14, 2011 at 17:32:09
one more thing about lables. See below example.

@echo off
echo I am not in any lable
goto Lable1

:Lable1
echo i m in lable1
echo.
goto lable3

:lable3
echo i m in lable 3.


Here, If you say your code to goto lable1, it not just goto lable1 but will execute further all lables like lable2,lable3 all. so using lables if you just want to exeucte that portion of batch then terminate the lable with Goto :eof.

Goto :Eof will tell the command processor to go to end of the file,no further lables is processed.as per my thinking using too much lables in batch file means lot of errors, I would suggest avoide using it until you understand at leeast a ltttle bit how it works.

Subhash Chandra.
www.s-chandra.co.cc


Report •

#5
February 14, 2011 at 23:57:07
Thank you all for the input you have provided here.
@Matt123 I now understand a lot more about the tokens and delims and how to use the for /f I will do more research regarding its other switches. Those two posts really helped me a lot.
@subhash chandra I understand what you are saying here. I will do that in the future. This batch file works perfectly. If it find the first search, it goes directly to the first copy and then to the first open. So it doesnt mix it around much but will keep that in mind.

Thank you for all of your help :)


Report •

#6
February 15, 2011 at 00:09:44
yep..it was not for this post..just you wanted to learn so ....

Subhash Chandra.
www.s-chandra.co.cc


Report •

Ask Question