TOP
2008-01-01

DOS Function Template - A function template with all features of a true DOS function

Description: The function template can be used as starting point for a new function. Complete the template into a useful function like this:
  • Rename the function
  • Add proper description for the function and its arguments
  • Fill in the function body
  • Return desired values
Script: Download: BatchFunctionTmpl.bat  
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
:myFunctionName    -- function description here
::                 -- %~1: argument description here
SETLOCAL
REM.--function body here
set LocalVar1=...
set LocalVar2=...
(ENDLOCAL & REM -- RETURN VALUES
    IF "%~1" NEQ "" SET %~1=%LocalVar1%
    IF "%~2" NEQ "" SET %~2=%LocalVar2%
)
GOTO:EOF

TOP
2008-01-01

DOS Batch - Functions - Keep your batch script clean, call DOS functions


TOP
2008-01-01

DOS Batch - Function Tutorial - What it is, why it`s important and how to write your own

Description: The assumption is: A batch script snippet can be named a function when:
  1. ... it has a callable entrance point.
  2. ... on completion execution continues right after the command that initially called the function.
  3. ... it works the same no matter from where it`s being called, even when it calls itself recursively.
  4. ... the variables used within a function do not conflict with variables outside the function.
  5. ... it exchanges data with the calling code strictly through input and output variables or a return code.
The benefits behind functions are:
  1. Keep the main script clean
  2. Hide complexity in reusable functions
  3. Test functions independently from the main script
  4. Add more functionality to your batch script simply by adding more functions at the bottom
  5. Don`t worry about the function implementation, just test it and use it

TOP
2008-02-19

:append - appends a string to a specific line in a text file

Description: call:append str file line
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
:append str file line -- appends a string to a specific line in a text file
::                    -- str  [in] - string to be appended
::                    -- file [in] - file name to append the string to
::                    -- line [in] - line number to append the string to, first line is 1, omit for last line
:$created 20060101 :$changed 20080219 :$categories FileManipulation
:$source https://www.dostips.com
SETLOCAL
set ap=%~1
set f=%~2
set c=%~3
if not defined c (
    set c=0
    for /f %%a in ('find /v /c ""^<"%f%"') do set c=%%a
)
(for /f "tokens=1,* delims=:" %%a in ('findstr /v /n "$$"^<"%f%"') do (
    if "%%a"=="%c%" (echo.%%b%ap%) ELSE echo.%%b
))>"%temp%.\t0815.txt"
move /y "%temp%.\t0815.txt" "%f%"
EXIT /b
Query: DtTutoFunctionsphp
Count: 94
top = Function

Function - 100
FunctionTutorial - 104
Condition - 121
StringOperation - 121
StringManipulation - 124
FileManipulation - 128
MyFirstBatchTutorial - 128
Tutorial - 130
Interfacing - 130
DosTips - 130
DateAndTime - 130
FileOperation - 130
FtpBatchScript - 131
BatchStepByStep - 133
UnitTest - 140
Encoding - 141
CommandIndex - 141
Snippets - 143
ServiceControl - 143
Commands - 144
XCopy - 150
Input - 150
Script - 150
Network - 150
Scripts - 150
Quine - 150
DOS - 150
String - 150
FileInfo - 150
Lookup - 150
Ftp - 150
Batch - 150
BatchFile - 150
Arithmetic - 150
DriveInfo - 150
Persistency - 152
Registry - 160
List - 160
Path - 160
Sitemap - 160
Debug - 160
Filter - 160
Template - 160
Color - 160
Experimental - 160
Progress - 160
Recursive - 160
Echo - 160
Window - 160
Regedit - 164
General - 170
Enabler - 170
Password - 170
Menu - 170
Sql - 170
Html - 170
Perl - 171
Array - 180