1. Date as a variable as part of the file name.
C:\Documents and Settings\simon>echo%date%
2008-09-09 Tuesday
C:\Documents and Settings\simon>echo%date:~5,5%
09-09
If we need to add a custom delimiter, such as the format you want to YYYY--MM--DD, you only need to remove the yyyy, MM, DD and then connect it together:
C:\Documents and Settings\simon>echo%date:~0,4%--%date:~5,2%--%date:~8,2%
2008--09-09
2. Command selection
C:\USERS\HP>CHOICE/C dme/m Defrag,mem,end
Defrag,mem,end [D,m,e]? D
@echo off
CHOICE/C dme/m Defrag,mem,end
if errorlevel 3 goto defrag (the highest number of error codes should be judged first)
if errorlevel 2 goto MEM
If Errotlevel 1 goto end
:d Efrag
C:dosdefrag
Goto END
: Mem
Mem
Goto END
: End
echo Good bye
3. Error judgment
@net use/%1ipc$%3/u: "%2"
@if errorlevel 1 goto failed
4. Combination commands
& Usage: First Command & second command [& Third command ...]
In this way, multiple commands can be executed at the same time, regardless of whether the command executes successfully
&& Usage: First command && second command [&& Third command ...]
In this way, multiple commands can be executed at the same time, and when the command that executes the error is executed, the subsequent command is not executed and all commands are executed if there is no error.
|| Usage: first Command | | Second command [| | | Third command ...]
In this way, multiple commands can be executed at the same time, and when the correct command is executed, no subsequent commands are executed, and all commands are executed if the correct command is not present;
Sample:
C:>dir z: && dir c:ex4rch
The system cannot find the path specified.
C:>dir c:ex4rch && dir z:
Volume in Drive C have no label.
Volume Serial number is 0078-59FB
Directory of C:ex4rch
2002-05-14 23:55 <DIR>.
2002-05-14 23:55 <DIR>.
2002-05-14 23:55 Sometips.gif
1 File (s) bytes
2 Dir (s) 768,671,744 bytes free
The system cannot find the path specified.
Sample:
C:ex4rch>dir Sometips.gif | | Del Sometips.gif
Volume in Drive C have no label.
Volume Serial number is 0078-59FB
Directory of C:ex4rch
2002-05-14 23:55 Sometips.gif
1 File (s) bytes
0 Dir (s) 768,696,320 bytes free
General Examples: See http://www.cnblogs.com/shiney/archive/2011/07/04/2097236.html
------------------------cut here and save as. bat or. cmd file---------------------------
@echo Preparing to delete all the default Shares.when ready pres any key.
@pause
@echo off
: Rem check parameters if NULL show usage.
If {%1}=={} goto:usage
: Usage
Echo.
Echo------------------------------------------------------
Echo.
Echo☆a Example for batch file☆
Echo☆[use batch file to change the Sysytem share properties.]☆
Echo.
Echo Author:ex4rch
echo Mail:[email protected] qq:1672602
Echo.
echo error:not enough parameters
: END
echo.
Echo---------------------------------------------- --------
Echo.
Echo Ok,delshare.bat have deleted all the share Assigned.
Echo. Any questions, feel free to mail [email protected] .
Echo
Echo.
Echo------------------------------------------ ------------
Echo.
: EOF
echo end of the batch file