compile bat

Discussion in 'Windows - Games' started by mestoman, Nov 24, 2006.

  1. mestoman

    mestoman Member

    Joined:
    Nov 24, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    11
    how do i do it?
     
  2. Jizmak

    Jizmak Regular member

    Joined:
    Dec 27, 2004
    Messages:
    2,528
    Likes Received:
    0
    Trophy Points:
    46

    POST YOUR QUESTION ONLY ONCE.

    People come here to help on there own FREE time,
    Follow the forum rules,And be patient,and someone will
    help you.

    All that said lets continue on.

    The batch language itself is pritty simple, fist off all our batch source code is writen in pure ASCII text format, and saved with the extension .bat. This can be acomplished with the use of a text editor such as notepad. A batch file is more or less a colection of DOS commands, as well as special batch spasific commands, plased sequentialy one on top of another. When the batch file is executed, the commands contained within are executed one by one as if you were typeing them in yourself. So why would you want to make a batch file? Well one example might be, you use a certian sequence of DOS commands every day when you start up your computer in the morning and it would be nice if we did not have to type them in manualy. Now, in batch we may use all of the commands available to our version of DOS, plus an aditional set of batch spasific commands. I will list some common DOS commands but for a complete refernce pick up a good DOS book at your local library:


    Not only may you use any of the DOS commands suported by your version of DOS, you may also use batch specific commands made for the purpose of batch file writeing:

    REM (remark, set comments. Used for documenting or commenting)
    ECHO (used to turn echoing on or off, as well can display an optional text message)
    PAUSE (suspends execution for spesified time period)
    FOR (execute a DOS command iteratively)
    GOTO (causes execution to jump to a spesified line, used for program branching)
    IF (conditional oporator used to execute a command only if condition is satisfied)
    SHIFT (shifts the contents of the program parameters)
    CALL (invokes a batch file, executable program or DOS command)

    The above is certianly not a complete list of commands available to the batch programer but it is certianly enough to produce some funky utilities. I have not provided the Syntax or how to use the commands, you should know how to get help on a command in DOS, but if you don't just launch DOS, type the command name followed by a space and /?. This will provide you with help.

    So what is the format of a batch file, I mean, how do you write a batch file? Well, let me show you an example:

    @ECHO OFF
    ECHO This program was created by Jizmak
    REM Move to C:\My Documents\Jizmak, if not exist create!
    IF NOT EXIST c:\mydocu~1\Jizmak\ md c:\mydocu~1\Jizmak
    cd c:\mydocu~1\Jizmak\
    REM Copy files specified in argument 1 to my directory
    copy %1 c:\mydocu~1\Jizmak\

    So what does the above batch file do? Simple, the first line turns off echo, however because echo was not previously off it would normaly display echo off on our screen, so to prevent this we preceed it by a @. This tells it not to display the command as it is being executed. Now that we have echo off we do not need to use @ because nothing will be displayed unless spesified otherwise. Next we tell DOS to display This program was created by Jizmak on the screen. Finaly we get to use rem to make a comment, this is for opur purposes and is ignored by DOS. It is so we have an idea what the next line does, when we look over our code next week. It is simular to comments in C. Now, we have a if conditional statement, we are saying to execute the command cd c:\mydocu~1\Jizmak only if c:\mydocu~1\Jizmak does not already exist. But what exactly is this c:\mydocu~1\Jizmak thingy? It is a directory on your hard drive. Actualy the directory is C:\My Documents\Jizmak but in DOS we cannot have long file names, we must stick to the 8.3 file nameing convention. So if our file name is greater then 8 characters long, we take the first 6 characters, ignoreing spaces, followed by a tilde ~ then the number 1. This makes My Documents mydocu~1 instead, thus satisfieing the 8 character limit. So apart from all that, it is clear as mud right? Good!
    So if C:\My Documents\Jizmak does not exist we create it. Now we use the DOS cd command to chage the current directory to our newly created directory. Finaly we include another comment to make things easy to read, then move on to a copy command. Now if you look up the copy command it sais it copys a file from one location to another. So what in the hell is this %1 thingy? I am glad you asked. When we execute our program later we will specify the program name (the name of the batch file) followed by a argument like so:

    batch1 a:\*.*

    So assumeing we named out batch file batch1.bat our first argument is a:\*.* which just hapens to be a file spesification spesifieing all the files on my floppy disk, assumeing our floppy drive (FDD) is labled a:. So now in our batch file, to use this argument we refernce it by %1, why %1 and not %0? because %0 hapens to be our program name :) and %2 would be the second parametner if we gave it one. So we are copying from wherever the first argument sais so, to the new directory C:\My Documents\Jizmak. The only major difernce between my batch file and the copy command is instead of copying to wherever we want, my batch program always copys to my own directory.

    Cheers!
     
    Last edited: Nov 24, 2006
  3. ddp

    ddp Moderator Staff Member

    Joined:
    Oct 15, 2004
    Messages:
    39,167
    Likes Received:
    136
    Trophy Points:
    143
    other posts hidden
     

Share This Page