BAT file written Basics


BAT scripting basics


BAT files, namely the batch (Batch) file in DOS or Windows system is the executable file. BAT file consists of a series of commands, which can contain calls to other programs.
Batch Definition: Batch File is a series of commands in a certain order as a set of executable text file with the extension BAT or CMD. These commands are collectively referred to as batch commands.
Baidu Encyclopedia introduction to the BAT: BAT (batch file types)

Batch file commonly used commands

echo display character after the command
echo on command after the statement will display the command line itself
echo off command after the statement will not display the command line itself
call call another batch file to
start calling external programs
pause pause batch file execution, will be prompted to press any key to continue
pause> nul pause batch file execution, but does not prompt
rem footnotes
dir displays the contents of the specified path
md create a subdirectory
cd changes the current directory
rd delete subdirectories
del delete a file
xcopy copy directory
copy copy file
type print file contents
move move folders
ping verification and remote computer connection
ipconfig to see the local ip address
arp display, modify aRP
net network related commands
tasklist display process
cls clear screen
> output to a file, such as E dir: \ xxx \ * .bat BAT> t.txt
title display DOS window title
color to set the background, foreground color
tree displays the specified path to the directory structure, such as tree e: \ xxx \ Book / f> tree.txt

Font color settings

Syntax:
Color XX XX represents a two-digit number, the former represents the background color, foreground color which represents the
commonly used colors:
0 Black, Blue 1, Green 2, 3 a pale green, red 4, 5 purple, yellow 6, 7 white, 8 gray, light blue 9, A light green, B blue, C light red, D light purple, E as a pale yellow, F bright white

Form size settings

Syntax:
the MODE CON: cols = width lines = height
cols show how many columns, lines indicate how many rows to display

Usage of common commands

tree

Function: Display all the file names in all the directory path and these directories specified drive
format: Tree [drive: path] [/ f] [> prt ]
Instructions:
shows all files in the directory and directory using / f show only omitted directory
using> prt time will print directories and files to a specified file

to you

Function: display the contents of the disk directory
format: dir [letter] [path] [/ p] [/ w]
Instructions:
Use / p will post information on split screen, use the / w display only the file name

md

Function: Create a new subdirectory
format: md [letter] [path] <subdirectory name>
Description:
letter you need to create a subdirectory of the letter of the drive letter represents the current default
path need to create a subdirectory of the parent directory name the default represents the creation in the current directory

xcopy

Function: with all files in the directory structure, copies the specified directory and directory
format: the xcopy [source disk:] <source path name> [target disk] [target path name] [/ s] [/ v ] [/ e]
using Note:
can not copy hidden files and system files
all files under the / s will copy the source directory and its subdirectories, but will use an empty directory with the copy does not copy empty directories, and / e

copy

Function: Copy one or more files to the specified path
format: Copy [Source disc] [path] <source file name> [target disk] [path] <destination file name>
Description:
file name can use wildcards *,? Target file name can be omitted


tips

  • You may be pressed on the keyboard Ctrl+Ckey combination to force termination of execution of a batch.
  • @ Available at the top of each command line is not displayed diverted command represents the runtime.

Reference article

Guess you like

Origin www.cnblogs.com/hai-feng/p/12316625.html