3rd August 04:23
"Frequently Asked Questions about MS-DOS batches"
Before posting an MS-DOS batch related question please be aware of
the information and solutions material already available, such as
243153 Dec 27 2003 ftp://garbo.uwasa.fi/pc/link/tsbat.zip
tsbat.zip Useful MS-DOS batch files and tricks, T.Salmi
Should you be interested in NT/2000/XP solutions in particular you might
wish to consider news:alt.msdos.batch.nt and
94268 Mar 31 2004 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
In case of grave difficulties in getting the files from Garbo archives
Sites with permission to mirror Garbo archives
The contents of the FAQ-like batch tips collection is given below.
For more MS-DOS batch or near information sources please see
This file TSBATIDX.TXT lists the contents of
1BATFAQ.TXT Assorted batch tricks and tips
1DOSTRIK.TXT Assorted MS-DOS tricks and tips
1PROMPT.TXT Tips on prompt usages with ansi
Alternatively available with the version number as
Please note. This collection is COMMAND.COM command processor based
MS-DOS batch material. Windows 3.11/95/98/Me dosbox quirks are not
covered, but practically all the tricks and tips will work in those
dosboxes. The 4DOS alternative command processessor is not covered.
Windows NT/2000/XP are platforms built on a different philosophy.
They are outside the scope of this collection and have a FAQ of
1) How can I make "@echo off" MS-DOS version independent?
2) Deleting all files without being prompted "Are you sure (Y/N)?"
3) Is it possible to nest for loops in batch files?
4) How can I check in a batch whether a directory exists?
5) Checking that a program is available at the current directory or at path
6) Is it possible to use subroutines and recursion in batches?
7) How can I convert a lowercase parameter to uppercase?
8) Is there an easy way to append a new directory to the path?
9) How can I compare if two files are identical?
10) Writing an empty line to the screen. How is that done?
11) A tip: Customizing the pause message
12) A tip: Complicated renaming of files with for
13) How can I check if the file name given included wildcards?
14) Is it possible to prevent the user from breaking the batch?
15) Can I prevent a break from bypassing the autoexec.bat?
16) How can I extract the extension of a file name?
17) Information on the quote character %
18) Eliminating auxiliary batches (making do with the main batch)
19) Utilizing the subst command in paths
20) How can I run a batch once a week (testing for the weekday)
21) How can I test if a given file name includes the path?
22) How can I display the time without having to press enter?
23) Alternatives for testing for the errorlevel value
24) About redirecting a batch file's output
25) How can I test if my batch has sufficient environment space?
26) Is there a simple trick to "disable" or hide a drive?
27) How can I send an escape sequence to the printer?
28) Is it possible to create a random string in a batch?
29) Is it possible in a batch to find out the length of a string?
30) How to obtain the MS-DOS version into an environment variable?
31) How can I find out the number of regular files on a drive?
32) How can I use a batch to augment line numbers to my text file?
33) Storing and returning to the original directory (push and pop)
34) Enticing the current date into an environment variable
35) A tip for power users. Identifying the individual PC.
36) For loop and redirection quirks
37) Is it possible to traverse a directory tree with a batch?
38) Is it possible to echo the redirection symbol in a batch?
39) How can I extract the file basename?
40) A batch to put user input into an environment variable
41) How can I get the last replaceable parameter given to a batch?
42) Creating an empty file if the file does not already exist
43) How can I change or remove the disk volume serial number?
44) How to pause in a batch for a preset number of seconds?
45) Where can I find a program to compile batches into COMs or EXEs?
46) How can I test whether a disk is empty or not?
47) How can I run a different batch depending on the weekday?
48) Can one put line numbers into a file with just batch commands?
49) How can I backup from the current directory files made today?
50) How can I traverse all files of a directory in a batch?
51) How can I step through a batch a command at a time to debug it?
52) How to find all files made or updated on a day or today?
53) How can I make a list of all my files and locate a certain file?
54) How can I tell if a program is running in a Windows dosbox?
55) How can I test if there is a disk in a floppy disk drive?
56) Could you please solve this problem for me with a batch?
57) How can I make a loop that is repeated a preset number of times?
58) How can I display the contents of the memory?
59) How get today's date elements into environment variables?
60) How can I find and copy the files updated today in a directory?
61) How can I test in a batch whether a TSR program has been loaded?
62) Putting the current drive letter into an environment variable.
63) How can I extract the drive letter from a full file path?
64) How can I write a "SLEEP" command to pause for a certain time?
65) How can put comments into a batch file?
66) How can I echo just the word "off" in a batch file?
67) How can I extract the first two characters of a file name?
68) How can I compare two numbers with batch commands?
69) All these solutions are for wimps. Why not rather use 4DOS?
70) How can I give more than the nine parameters to a batch?
71) How can I update copy files from one directory to another?
72) How can I best clear all the files from my TEMP directory?
73) How can I check the number of parameters given to a batch?
74) How can I locate and e.g. delete all *.TMP files on a drive?
75) How can I rename all files sequentially in a directory?
76) How to search all the *.txt files on a drive for a word?
77) How can I give multiple commands on one line?
78) Is there a batch to individually zip each file in a directory?
79) A batch to substitute a string through a set of text files?
80) Where do I find a good book or WWW page on batch programming?
81) How to read a file's date and time into environment variables?
82) How would I get a beep in a batch file?
83) Y2K: My old BIOS gives a wrong year at boot. How can I fix it?
84) Is there a batch to drop the first letter of a file name?
85) How do I close the command window once my batch file has run?
86) Is MS-DOS batch programming going to die along with W2K?
87) How can I test for the existence of a substring in a string?
88) How can I put MS-DOS FIND results into an environment variable?
89) How to get months as letters and years in four digits in DIR?
90) Isn't MS-DOS dead with W2K? So why bother with MS-DOS batches?
91) How can I exit the called batch without returning to the first?
92) How do I create a sequence of directories from 001 to MaxValue?
93) How do I add +1 to a variable in a batch?
94) How to copy the errorlevel into a variable in a batch?
95) How can I test for a zero byte file? Or against a larger size?
96) How to show the last N lines of a file using DOS batch files?
97) How do I get the path of a file located somewhere on my disk?
98) How to read a file's attributes into environment variables?
99) Is it possible to echo without linefeed like the Unix echo -n?
100) How can I detect the F1-F10 function keys in a batch?
101) How can I get the free size and total size of a drive?
102) How can I search for a string through a directory of files?
103) How do I find the largest numeric extension and add +1 to it?
104) How do I run the latest executable from the default directory?
105) How can I determine if ANSI.SYS is loaded?
106) How do I get the last drive into an environment variable?
107) How can I calculate the number of lines in a file?
108) Is it possible to save and later restore the command history?
109) Is it possible to change just one line of a file with a batch?
110) Is it possible to delete lines by their line numbers only?
111) How can I tell what drive has been allocated by ramdrive.sys?
112) How can in insert a line in the middle of a file with a batch?
113) What is difference between MS-DOS and various Windows batches?
114) Is it possible to display comments from the config.sys file?
115) Can I split a single command over multiple lines in a batch?
116) How can I get yesterday's date into an environment variable?
117) How do I get the 3rd word from the 5th line of a text file?
118) How to put the content of text file into a variable?
119) How do I get the three oldest and latest files of a directory?
120) Hint: Displaying an ASCII (hex) value table
121) How to make %0 include the full path of the called batch file?
122) How can I test if a file is dated less than hour ago?
123) How I can (re)set the screen text and background colors?
124) How do I get the echo status into an environment variable?
125) How can I delete all empty directories on a drive?
126) How can I put an = into an environment variable?
127) How can I reverse a word or an entire line?
128) How can I add date and time to each line of a text file?
129) Is a column-sensitive search possible through a text file?
130) How can I calculate the number of words in a text file?
131) How can I put the lines of a text file into a reverse order?
132) How can I add 5:23:11 to the current time?
133) How do I find out the number of parameters given to my batch?
134) How to remove the first two characters throughout my text file?
135) Can one calculate the difference between two times in a batch?
136) Is it safe to use debug or other similar tools in batches?
137) How can I retrieve a keyword from a text file into environment?
138) How to find if there is an identical file elsewhere on my HD?
139) How can I cut a textfile at, say 8000 characters?
140) How can I remove all empty lines from a text file?
141) Can I calculate factorials in a batch? Do I need recursion?
142) How can I extract or delete a range of lines from my textfile?
143) How do I get the week number? What about the day of the year?
144) How do I rename myfile.txt to myYYMMDD.txt with current date?
145) How do I insert a pagebreak into a textfile every 25th line?
146) Is it possible to count how many times a batch has been called?
147) Can I enter a password to batch without it being echoed?
148) How can I create a dummy file with a given filesize?
149) A batch to compare which of two files is the more recent?
150) Can I convert DEC to HEX in a batch file, and vice versa?
151) How do I find and print the longest line in a text file?
152) Can I remove the comment from all .zip files in a directory?
153) A NOT in batch? E.g. copy a directory's all but .exe files.
154) I need the for loop to append info to an environment variable?
155) How do I remove consecutive duplicate lines from a file?
156) How can I columnize a single column into columns of e.g. five?
157) Is it possible to sort a text file by the length of its lines?
158) Can I get the full file names AND the file size and datestamp?
159) How can I convert a Unix text file to MS-DOS? And vice versa?
160) How do I add a space after every fourth character on a line?
161) How do I get all but the last line, and replace last by "End"?
162) How can I calculate how many times "e" occurs in my text file?
163) Is it possible to concatenate two text files side by side?
D1) Is it possible to disable dangerous MS-DOS commands?
D2) When and How to Simulate disk partitioning?
D3) A config.sys and autoexec.bat example
D4) Stepping through config.sys and autoexec.bat command by command
D5) Can I get rid of the annoying "Insert diskette for drive B:"?
D6) Conditional deleting of files
D7) Selected Doskey macro examples
D8) Bypassing or stepping through config.sys and autoexec.bat
D9) What does "Out of environment space" mean? How do I get more?
D10) How can I delete a file/directory with a space in the name?
P1) Changing the shell prompt
P2) Redefining keys
P3) Ansi prompt art
P4) Debugging the prompt
All the best, Timo
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 126.96.36.199
Department of Accounting and Business Finance ; University of Vaasa
mailto:email@example.com <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html