Computing.Net > Forums > Programming > Simple Batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Simple Batch file

Reply to Message Icon

Name: SteadyLoungin05
Date: July 29, 2004 at 09:49:15 Pacific
OS: Win XP Pro
CPU/Ram: P4, 1.5Ghz, 256MB RAM
Comment:

Hey all -

I am new to DOS and am still learning all the commands.

I have looked on google for some tutorials and what not and have found some good information, but nothing beats this website.

I am writing a simple batch file, just for fun, that changes to a directory with music videos in it, displays my name, displays a simple message, and plays a video out of the directory.

While I have not put in the code for the change of directory, I have executed this .bat file with a predetermined video - What I would ultimately like to accomplish is to either have a random video play, or have user input as to which video he/she would like to see.

I realize that the code for this may be way over my head, given I'm a newbie to DOS, but I was wondering if anyone could offer any help to point me in the right direction?

I like what I have been able to do in DOS so far and I want to learn more, so any and all help is greatly appreciated!!

I'm Rick James BITCH!


Oops almost forgot - Here is what I have already, minus the change directory.

@echo off
cls
Echo Hey, my name is Mike.
pause
Echo Enjoy the video!
pause
start mplayer2 "video.mpg"

Thanks again!



Sponsored Link
Ads by Google

Response Number 1
Name: BlueRaja
Date: July 29, 2004 at 13:07:13 Pacific
Reply:

I don't believe DOS has any integrated random number generators, although you could code one in about 2 minutes with debug (but then, if you knew how to do that, you wouldn't be learning batch file programming O_o). Otherwise, you could look online for a simple RNG .com or .exe file.

As far a user input goes...geeze it's been a long time..
I think you pipe input from the console (CON)...otherwise you could always take arguments from the commandline using %1-%9
I'm sure you'll get to that in your..erm..lessons


0

Response Number 2
Name: IVO
Date: July 29, 2004 at 13:37:28 Pacific
Reply:

Stated there is no DOS in Windows NT/2K/XP (what you see is actually the NT System Console) and DOS is emulated by the NTVDM (Virtual DOS Machine), you can enjoy the power of the NT extended batch language, only in surface resembling the plain DOS scripting.

So your script can be transformed into

@Echo Off
ClS
Echo Hey, my name is Mike.
Pause
CD C:\MyVideo
:LOOP
Set /P Video=Enter the Video you like^>
If /I %Video%.==EXIT. GoTo :EOF
If exist %Video% GoTo :PLAY
Echo Sorry... Video not found, try again
Echo Type EXIT to quit
GoTo :LOOP

:PLAY
Echo Enjoy the video!
Pause
Start MPlayer2 "%video%.mpg"

Where CD C:\MyVideo changes the current directory and it is better to have no blanks embedded.
Among the extensions there is a random number generator too (the %Random% variable)...

What you see above is only a taste and works under the NT Windows family (NT/2K/XP).
To learn about commands at prompt type the command's name followed by /?, e.g.
Set /?
A fast tutorial stems out even if not always easy to understand.


0

Response Number 3
Name: SteadyLoungin05
Date: July 29, 2004 at 17:51:48 Pacific
Reply:

I have modified my code a little bit - I decided to start out, I wanted to just say hey, this is my name, and this is a sample batch file.

Then I want to ask the userif he/she would like to watch a music video. By pressing "y" or "n", it should do either of two things:

If "y", I would like the video to run as it currently does.

If "n", display a message then exit the prompt.

As of right now, both "y" and "n" open up the video and I'm completely stumped as to how to change the code.

I have looked at multiple websites, including the DOS help, but just don't understand the IF or SET commands. If seems like the syntax is right, but I'm just not getting it to execute how I want.

Here is a copy of my code so far - I love what I've been able to do - I'm close to finishing my first batch file and I want this one to run smoothly.

Thanks for ANY HELP.

Here is my code:

@echo off
cd D:\My Videos
cls
echo Hey this is Michael. I just wrote this simple batch file.
pause
Would you like to watch a music video:^>
SET yes=y
IF NOT "%yes%"=="y" GoTo :PLAY
IF NOT "%yes%"=="n" GoTo :THANKS
GoTo :END
:PLAY
echo Enjoy the video!!!!!
start mplayer2 "Nelly - Air Force 1.mpg"
GoTo :END
:THANKS
echo That's too bad - Thanks for stopping by!!!
GoTo :END

:END


P.S - This is NOT for homework - I want to learn DOS and this is my first attmept at a batch file!

I'm Rick James BITCH!


0

Response Number 4
Name: IVO
Date: July 30, 2004 at 02:13:14 Pacific
Reply:

Hi SteadyLoungin05,

you do not get the desidered behavior as there are some mistakes in youryour script.
What I suggest to fix is valid under Windows NT/2K/XP ONLY (the system you say to run in your post), otherwise let me know and I can show you a real plain DOS equivalent.
* Replace
cd D:\My Videos
with
CD "D:\My Videos"

* Replace
Would you like to watch a music video:^> SET yes=y
with
:LOOP
Set /P Video=Would you like to watch a music video [Y/N]:

* Replace
IF NOT "%yes%"=="y" GoTo :PLAY
IF NOT "%yes%"=="n" GoTo :THANKS
with
If /I "%Video%"=="Y" GoTo :PLAY
If /I "%Video%"=="N" GoTo :THANKS
Echo Please...Enter Y or N
GoTo :LOOP

At :END add the command
Set Video=
to clean up the environment from the Video variable.

The Set /P sets the Video variable to the value entered displaying the string at the rigth of the equal sign.
The If /I ignores lowercase/upcase i.e. Y=y.
The path in CD must be enclosed by " as it contains blanks.

If you need more help, post again.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Simple Batch file

Need help to make a simple batch file www.computing.net/answers/programming/need-help-to-make-a-simple-batch-file/20286.html

simple batch file prog q.. www.computing.net/answers/programming/simple-batch-file-prog-q/14278.html

Simple batch file www.computing.net/answers/programming/simple-batch-file/12918.html