Ano ang BAT file?
Ang BAT file ay kilala bilang isang batch file na tumatakbo sa DOS at lahat ng bersyon ng Windows, sa ilalim ng cmd.exe. Binubuo ito ng isang serye ng mga line command sa plain text na isasagawa ng command-line interpreter para magsagawa ng iba’t ibang gawain, tulad ng pagpapatakbo ng mga maintenance utility sa loob ng Windows o pagsisimula ng mga tipikal na programa. Ang isang batch file ay maaaring magsama ng anumang command na maaaring tanggapin ng interpreter sa interactive na paraan at gamitin ang istruktura ng code na nagbibigay-daan sa conditional branching at looping gaya ng nakasulat sa loob ng batch file.
BAT file format
Ang format ng BAT file ay simpleng script na isinama upang i-automate ang mga pagkakasunud-sunod ng command na paulit-ulit sa kalikasan. Ang terminong “batch” ay ginagamit para sa pagpoproseso ng batch, Maaari itong ituring na “non-interactive na pagpapatupad”. Samakatuwid ang isang batch file ay maaaring hindi magproseso ng isang batch ng maraming data. Sa lumang Disk Operating System (DOS), ang batch file ay pinatakbo sa ilalim ng command line interface sa pamamagitan ng pag-type ng filename at ang extension na .bat. Ang naunang Microsoft graphical interface based operating system gaya ng Microsoft Windows ay nakadepende sa DOS. Kinailangan ng mga user na gumamit ng DOS para magsagawa ng mga tipikal na operasyon tulad ng pagkumpuni, pag-optimize o muling pag-install ng Windows. Nang maglaon, ipinakilala ng Microsoft ang Windows NT na hindi nakadepende sa operating system ng DOS. Samakatuwid, ang mga batch file ay maaaring patakbuhin sa pamamagitan ng paggamit ng Command Prompt o cmd.exe sa modernong mga operating system ng Microsoft.
Mga parameter ng batch file
Sinusuportahan ng command prompt ang ilang espesyal na variable gaya ng %0, %1 hanggang %9 upang sumangguni sa pangalan at path ng batch job at ang siyam na parameter ng pagtawag mula sa loob ng batch job. Ang mga hindi umiiral na parameter ay pinapalitan ng isang string na may zero-length. Bagaman, maaari silang magamit katulad ng mga variable ng kapaligiran, ngunit hindi nai-save sa kapaligiran. Tinutukoy ng Microsoft at IBM ang mga variable na ito bilang mga kapalit na parameter, Habang ipinakilala ng Novell, Digital Research, at Caldera ang terminong mga variable na kapalit para sa kanila.
Narito ang ilang kapaki-pakinabang na Batch file command:
Command | Description |
---|---|
VER | This batch command shows the version of MS-DOS you are using. |
ASSOC | This is a batch command that associates an extension with a file type (FTYPE), displays existing associations, or deletes an association. |
CD | This batch command helps in making changes to a different directory, or displays the current directory. |
CLS | This batch command clears the screen. |
COPY | This batch command is used for copying files from one location to the other. |
DEL | This batch command deletes files and not directories. |
DIR | This batch command lists the contents of a directory. |
DATE | This batch command help to find the system date. |
ECHO | This batch command displays messages, or turns command echoing on or off. |
EXIT | This batch command exits the DOS console. |
MD | This batch command creates a new directory in the current location. |
MOVE | This batch command moves files or directories between directories. |
PATH | This batch command displays or sets the path variable. |
PAUSE | This batch command prompts the user and waits for a line of input to be entered. |
PROMPT | This batch command can be used to change or reset the cmd.exe prompt. |
RD | This batch command removes directories, but the directories need to be empty before they can be removed. |
REN | Renames files and directories |
REM | This batch command is used for remarks in batch files, preventing the content of the remark from being executed. |
START | This batch command starts a program in new window, or opens a document. |
TIME | This batch command sets or displays the time. |
TYPE | This batch command prints the content of a file or files to the output. |
VOL | This batch command displays the volume labels. |
ATTRIB | Displays or sets the attributes of the files in the curret directory |
CHKDSK | This batch command checks the disk for any problems. |
CHOICE | This batch command provides a list of options to the user. |
CMD | This batch command invokes another instance of command prompt. |
COMP | This batch command compares 2 files based on the file size. |
CONVERT | This batch command converts a volume from FAT16 or FAT32 file system to NTFS file system. |
DRIVERQUERY | This batch command shows all installed device drivers and their properties. |
EXPAND | This batch command extracts files from compressed .cab cabinet files. |
FIND | This batch command searches for a string in files or input, outputting matching lines. |
FORMAT | This batch command formats a disk to use Windows-supported file system such as FAT, FAT32 or NTFS, thereby overwriting the previous content of the disk. |
HELP | This batch command shows the list of Windows-supplied commands. |
IPCONFIG | This batch command displays Windows IP Configuration. Shows configuration by connection and the name of that connection. |
LABEL | This batch command adds, sets or removes a disk label. |
MORE | This batch command displays the contents of a file or files, one screen at a time. |
NET | Provides various network services, depending on the command used. |
PING | This batch command sends ICMP/IP “echo” packets over the network to the designated address. |
SHUTDOWN | This batch command shuts down a computer, or logs off the current user. |
SORT | This batch command takes the input from a source file and sorts its contents alphabetically, from A to Z or Z to A. It prints the output on the console. |
SUBST | This batch command assigns a drive letter to a local folder, displays current assignments, or removes an assignment. |
SYSTEMINFO | This batch command shows configuration of a computer and its operating system. |
TASKKILL | This batch command ends one or more tasks. |
TASKLIST | This batch command lists tasks, including task name and process id (PID). |
XCOPY | This batch command copies files and directories in a more advanced way. |
TREE | This batch command displays a tree of all subdirectories of the current directory to any level of recursion or depth. |
FC | This batch command lists the actual differences between two files. |
DISKPART | This batch command shows and configures the properties of disk partitions. |
TITLE | This batch command sets the title displayed in the console window. |
SET | Displays the list of environment variables on the current system. |
Halimbawa ng BAT file
Ang mga batch na script ay karaniwang nai-save bilang simpleng mga text file; naglalaman ng mga utos na maipapatupad sa isang pagkakasunud-sunod. Ang mga file na ito ay nai-save gamit ang .bat extension; kinikilala at isinagawa sa pamamagitan ng paggamit ng Command Interpreter software. Ang software na ito ay native na available sa Microsoft Windows na may pangalang cmd.exe.
Narito ang isang sample na Batch Script na nagtatanggal ng lahat ng mga file sa kasalukuyang direktoryo:
:: Deletes All files in the Current Directory With Prompts and Warnings
::(Hidden, System, and Read-Only Files are Not Affected)
:: @ECHO OFF
DEL . DR