Professional Documents
Culture Documents
Batfiles: The DOS batch file programming handbook & tutorial © 1997-
2003 by Laurence Soucy
12. A timed delay (wait/sleep) which can not be interfered with from the keyboard.
:: Substitute 5 with the desired number of seconds, up to 99.
TYPE nul |CHOICE.COM /N /CY /TY,5 >nul
29. Echo pipes and redirection characters to the screen or to another file.
ECHO @PROMPT a+b $g c+d$_ > %temp%.\spchar1.bat
COMMAND/E:2048/C %temp%.\spchar1.bat |FIND "+" >%temp%.\results.txt
DEL %temp%.\spchar1.bat
31. Limit DIR output to only the file or directory you specify.
In cases where you are looking for an extensionless file or directory, only the name you
specify will be in the DIR output, even though there may exist one or more files with the
same basename and an extension. It can be used on all files because a dot following a file
with an extension is ignored.
DIR/A-D/-P FileName.
DIR/AD/-P DirName.
33. Xcopy one file to another without being asked if it's a file or directory.
ECHO F |XCOPY.EXE file1 file2
34. Xcopy a file to another directory w/o pipe.
XCOPY c:\example1.fil w:\temp\
38. Place a line without a CR/LF (Carriage Return/Line Feed) into a file.
After creating this input file which has an End Of File character as its last character, you
can TYPE the input file into a new batch file which will not have a CR/LF. See FAQ 57.
:: setvar.inp
@ECHO off
:: EOF character created in edit by Ctrl+P+Z
SET %1=EOF
39. Get input from file into variable. {last modified Oct. 19, 2002}
Where result1.dat contains command output or other text. This example places the
current directory into a variable.
:: result.bat
@ECHO off
CD > result1.dat ECHO. >> result1.dat
DATE < result1.dat | find "):" > result1.bat
ECHO set curdir=%%4> enter.bat
FOR %%C IN (CALL DEL) DO %%C result1.bat
DEL enter.bat
:: %optional% DEL result1.dat
:: %optional% ECHO. current directory is %curdir%
40. Timestamp and/or datestamp (touch) a file with the current system date and
time.
COPY/Y filename /B+,,
44. Display number of files in directory, bytes used and bytes free.
DIR/W c:\bat |find "y"
Includes subdirectories:
DIR/W/S c:\bat |find "y" |more
:recurs
SET 1stfile=%1
IF not "%fspec%"=="" ECHO. 1st %fspec% file in directory is %1
IF "%fspec%"=="" ECHO. 1st file in directory is %1
::