| DosTips.com ... for VISTA,XP,NT,Server 2000,Server 2003,Server 2008 |
|
Last update: Apr 1, 2009 |
|
| |
|
Executing a FTP script.
|
|
|
Toggle menu options, persist settings for the next run.
|
|
|
Template with version history, window title, delayed automatic exit.
|
|
|
A collection of batch files.
|
|
|
Quickly find a file on your hard drive.
|
|
|
Search a file and replace all occurrences of a string with another string.
|
|
|
File Transfer with FTP, One-File Solution.
|
|
|
Embed other languages into your batch, like: Perl, SQL, FTP, ...
|
|
|
Show progress in batch using the title bar
|
|
|
A pretty short DOS Batch Quine.
|
|
|
A pretty short DOS Batch Quine.
|
|
|
A pretty short DOS Batch Quine.
|
|
|
A DOS Batch Quine that makes no assumption.
|
|
|
A DOS Batch Quine that makes no assumption.
|
|
|
A DOS Batch Quine that makes no assumption.
|
|
|
Likely the shortest DOS Batch Quine ever.
|
|
|
Simple menu framework. Plug in a new menu item and coresponding script as single function block.
|
|
|
Sorting that handles numbers as numbers not text.
|
|
|
Ftp script to download only files that don`t exist in local folder, i.e. to avoid overwrite
|
|
|
FTP script and batch in a single file.
|
|
|
Creating FTP script on the fly at runtime and using variables within the FTP script.
|
|
|
A function template with all features of a true DOS function.
|
|
|
Command reference in HTML format via batch.
|
|
|
Convert the file date into Julian Days to determine the age of a file age in days.
|
|
|
SQL script and dos batch script in one file, the One-File Solution
|
|
|
Run SQL scripts with parameters passed in from the batch script.
|
|
|
Perl script and batch in a single file.
|
|
|
Perl script and batch in a single file.
|
|
|
Template with simple init and exit.
|
|
Description: | The FTP command support the "-s:ftpscript.txt" option. The FTP commands listed in ftpscript.txt will automatically run after FTP starts. The FTP command can be started from a batch file. Example:
| ||
Script: | |||
Script Output: |
|
Description: | Example - Installation Framework.
This example shows how to enhance a program with persistent settings that can be changed using a menu. I.e.:
| ||
Script: | Download: BatchInstall.bat
| ||
Script Output: |
|
Description: | This advanced batch template features:
| ||
Script: | Download: BatchDelayOnExit.bat
|
Description: | This batch creates a lookup list of all files on the C: drive.
| ||
Script: | Download: BatchListOfFiles.bat
| ||
Script Output: |
|
Description: | This batch allows string substitution in a text file. It parses each line of a text file for a particular string and replaces it with another string.
| ||
Script: | Download: BatchSubstitute.bat
|
Description: | Showing progress in the output window seems impractical in DOS batch, since there is no way to
overwrite a previews output for an updated progress status during each progress tick. Using the
ECHO command is not nice, screen content quickly scrolls out of sight. A practicable alternative
may be to use the window TITLE for the progress message. A nice side effect is that you can
minimize the batch window and still observe the progress output in the task bar, since the task
bar text will always reflect the window title text. | ||
Script: | Download: DosProgress.bat
| ||
Output: |
Description: | A Quine is a program who`s only output is it`s program code.
Run the Quine using the following command in order to make sure Delayed Expansion is disabled and ECHO is OFF: C:> Cmd /Q /V:Off /C BatchQuine.bat If you use this code make sure to add a reference to DosTips.com. | ||
Script: | Download: BatchQuine_1_3.bat
| ||
Script Output: |
|
Description: | A Quine is a program who`s only output is it`s program code.
This little Quine has been developed by Peter Hartmann. Run the Quine using the following command in order to make sure Delayed Expansion is disabled and ECHO is OFF: C:> Cmd /Q /V:Off /C BatchQuine.bat If you use this code make sure to add a reference to DosTips.com. | ||
Script: | Download: BatchQuine_2_2.bat
| ||
Script Output: |
|
Description: | A Quine is a program who`s only output is it`s program code.
Run the Quine using the following command in order to make sure Delayed Expansion is disabled and ECHO is OFF: C:> Cmd /Q /V:Off /C BatchQuine.bat If you use this code make sure to add a reference to DosTips.com. | ||
Script: | Download: BatchQuine_1_1_1.bat
| ||
Script Output: |
|
Description: | A Quine is a program who`s only output is it`s program code.
This little Quine has been developed by Peter Hartmann. If you use this code make sure to add a reference to DosTips.com. | ||
Script: | |||
Script Output: |
|
Description: | A Quine is a program who`s only output is it`s program code.
This little Quine has been developed by Peter Hartmann. If you use this code make sure to add a reference to DosTips.com. | ||
Script: | Download: BatchQuine_1_1.bat
| ||
Script Output: |
|
Description: | A Quine is a program who`s only output is it`s program code.
This little Quine has been developed by Peter Hartmann. If you use this code make sure to add a reference to DosTips.com. | ||
Script: | Download: BatchQuine_2_1.bat
| ||
Script Output: |
|
Description: | A Quine is a program who`s only output is it`s program code.
Run the Quine using the following command in order to make sure Delayed Expansion is disabled and ECHO is OFF: C:> Cmd /Q /V:Off /C BatchQuine.bat If you use this code make sure to add a reference to DosTips.com. | ||
Script: | Download: BatchQuine_1_3.bat
| ||
Script Output: |
|
Description: | This simple menu framework parses itself for batch labels of certain signature and lists them as menu items. The self-parsing feature makes the menu generic. New menu items can be inserted by adding new function blocks without changing the menu infrastructure. Features:
| ||
Script: | Download: BatchMenu.bat
| ||
Script Output: |
|
Description: | This batch sort`s text by handling the first number found in each line as real number not as text. E.g.:
| ||
Script: | |||
Script Output: |
|
Description: | This batch connects twice to the FTP server. First time it retrieves a list of files
on the FTP server. This list is being trimmed to contain only files that don`t
already exist locally. The files in the trimmed list are then downloaded during a second
connection.
Note: Since all files are passed into the FTP`s MGET command there might be a limit to the number of files that can be processed at once. | ||
Script: | Download: BatchFtpGetNewFilesOnly.bat
|
Description: | Embed FTP script into a batch script. Add this line at the beginning of the FTP script: @ftp -i -s:"%~f0"&GOTO:EOFThe "FTP -s:ftpscript.txt" option executes a FTP script wheres "%~f0" resolved to the name of the running batch file.
"GOTO:EOF" ends the batch script and makes sure the FTP script doesn`t run as part of the batch.
| ||
Script: | |||
Script Output: |
|
Description: | This batch executed the FTP script embedded within the batch. All variables in the FTP script will be resolved. The FOR loop extracts the FTP script into a temporary file. It the ECHO command is being CALLed for each line in order to resolve the variables. Variables can be used within the FTP script the same way as in a batch script, including any string manipulation and command line arguments like %1 %2 %~n0 %* and so on. All batch lines start with semicolon so that they will be ignored by the FOR loop. Semicolon is the default end-of-line (EOL) character used by the FOR command. |
Script: |
Description: | The function template can be used as starting point for a new function. Complete the template into a useful function like this:
| ||
Script: | Download: BatchFunctionTmpl.bat
|
Description: | A DOS batch that creates a well formatted HTML file listing the help output for all DOS commands. Features:
|
Script: | |
Script Output: |
Description: | Date and Time functions are useful for:
The example in this section demonstrates how to use the :ftime function to determine the age in days of all files in the temp directory. Two variables are used
Using Delayed Expansion and exclamation marks around environment variables ensures that the `tfile`variable is substituted properly during each loop. Read more about this behavior in the SET command help (bottom half of the help text). | ||
Script: | Download: BatchFTime.bat
| ||
Script Output: |
|
Description: | Embedding SQL script within a batch script is just as easy. The following batch script executes itself in SQL context. The trick is the GOTO command in the first line of the script. When executing GOTO START in batch context than the command processor will jump to the label ":START" and execute the batch script. The batch script will then run the OSQL.EXE using the batch file itself as SQL file argument to be executed. When subsequently executing the GOTO START line in SQL context, the query language processor will jump to the label "START:" and execute the SQL queries. In fact the file can be opened and executed in Query Analyzer as is, since the batch script in the file looks like a comment to the query language processor. | ||
Script: | Download: Batch4SQL.bat
|
Description: | Now we can embed SQL queries into a batch file. But how can we pass arguments from the batch script into SQL? This can be done using a temporary table. Temporary tables live as long as the connection to the SQL Server. But how can we fill a temporary table with runtime data and execute the embedded SQL script without creating two separate SQL Server connections by calling OSQL.EXE twice? The trick is that OSQL allows to use the -i and -q option at the same time whereas:
| ||
Script: | Download: Batch4SQL2.bat
|
Description: | It`s nice not to have to type "perl -s Batch4Parl.pl" into the command line and rather being able to just double click a Perl script in Explorer. The trick of renaming the Perl .pl to a batch .bat file and wrapping a batch script around the Perl script is well known under Perl monks. However the solution I have seen so far needed batch code before and after the Perl script where as the solution presented below only needs some lines of DOS at the top. The added DOS script is generic and works independent from the name of the file. When running the batch the DOS command interpreter will read the first lines and execute the file itself in Perl context. |
Script: |
Description: | This example works just as the previews one but will wait 4 seconds before the application finally closes. This is just enough time to inspect the screen output before the window vanishes. The delay can probably be done much easier in Perl, but somebody just starting on Perl might find this still useful. | ||
Script: | Download: Batch4Perl2.bat
|
Description: | The function template can be used as starting point for a new batch. |
Script: |