Batch File Programming

You can get a few DOS batch file utilities from here (2k) (20 Dec 1998).
These utilites include items like getting the current weekday, day of the month, current hour, a Y or N response, etc..

Have a look at the following links for more on batch files:
http://www.netikka.net/tsneti/info/tscmd.htm
http://home7.inet.tele.dk/batfiles/main/links.htm
http://www.nc5.infi.net/~wtnewton/batch/
http://www.99-bottles-of-beer.net/language-dos-batch-1606.html
http://www.schnaader.info/sickbat.html
http://lf.8k.com/BAT/BAT.HTM
http://student.vub.ac.be/~dvandeun/batcoll.all
http://www.infionline.net/~wtnewton/batch/
http://www.lagmonster.org/docs/DOS7/links.html
http://garbo.uwasa.fi/pc/batchutil.html
ftp://garbo.uwasa.fi/pc/link/
http://4dos.info/4batfaq.htm


The following is usually posted to one of the batch file related newsgroups.
It should help a lot.

Dear Readers,

Before posting an MS-DOS batch related question please be aware of
the information and solutions material already available, such as

 222794 Apr 17 2002 ftp://garbo.uwasa.fi/pc/link/tsbat.zip
 tsbat.zip Useful batch files and tricks, linked from /pc/ts, T.Salmi

The contents of the FAQ-like batch tips collection is given below.
For more MS-DOS batch or near information sources please see

 http://www.uwasa.fi/~ts/http/http2.html#batch

This file TSBAT.IDX 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
         in ftp://garbo.uwasa.fi/pc/link/tsbat.zip
         Alternatively available with the version number as
         ftp://garbo.uwasa.fi/pc/ts/tsbat75.zip

Please note. 4DOS, Windows 3.11/95/98/Me and NT/2000/XP aspects and
quirks are not covered by this material.
--------------------------------------------------------------------
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?
--------------------------------------------------------------------
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 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:ts@uwasa.fi   ; FIN-65101,  Finland
Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html