├── Images └── ReadMe │ └── cmd.png ├── LICENSE ├── README.md └── files ├── ApplicationInstall.bat ├── BOOTDISK.BAT ├── DOSSTART.BAT ├── FCOUNT.BAT ├── FCOVER.BAT ├── FTIME.BAT ├── LCOUNT.BAT ├── LCOVER.BAT ├── MAKAPT15.BAT ├── MAKFRE15.BAT ├── PINGNAME.BAT ├── PINGNUM.BAT ├── Remove_Cbs_Logs.bat ├── SETUPNM.BAT ├── Start17.bat ├── VCVARS32.BAT ├── args.bat ├── autoexec.bat ├── backbat.bat ├── backbat2.bat ├── badpath.bat ├── copies.bat ├── cp.bat ├── cp2.bat ├── exist.bat ├── go.bat ├── go2.bat ├── hello.bat ├── keep.bat ├── main1.bat ├── main2.bat ├── mbcopy.bat ├── mycopy.bat ├── myvar.bat ├── myvar2.bat ├── newname.bat ├── p.bat ├── param.bat ├── param2.bat ├── param3.bat ├── param4.bat ├── param5.bat ├── rems.bat ├── rems2.bat ├── safepath.bat ├── safepath9x.bat ├── shift.bat ├── shifter.bat ├── str1.bat ├── str2.bat ├── str3.bat ├── sub.bat ├── tf1.bat ├── tf2.bat ├── tf3.bat ├── tf4.bat ├── tf5.bat ├── tf6.bat └── zero.bat /Images/ReadMe/cmd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Archive-projects/Batch-File-examples/84bb1dda319bafc91a83fc58c590a541010344b9/Images/ReadMe/cmd.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Anthony Duguid 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Batch File Examples 4 | Various batch files 5 | 6 | 7 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE "MIT License Copyright © Anthony Duguid") 8 | [![Latest Release](https://img.shields.io/github/release/Archive-projects/Batch-File-examples.svg?label=latest%20release)](https://github.com/Archive-projects/Batch-File-examples/releases) 9 | [![Github commits (since latest release)](https://img.shields.io/github/commits-since/Archive-projects/Batch-File-examples/latest.svg)](https://github.com/Archive-projects/Batch-File-examples/commits/master) 10 | 11 | ----- 12 | 13 | ## Table of Contents 14 | |File Name |Description/Usage | 15 | |:------------------------------------------|:-----------------------------------------| 16 | |[args.bat](/files/args.bat)|Display the use of spaces with echo.| 17 | |[autoexec.bat](/files/autoexec.bat)|AUTOEXEC.BAT file from PC in L-1. Mostly set commands. PATH is a special command which sets the PATH variable. Notice how the Pervasive.SQL 2000 install has messed up the batch file by putting commands before the @Echo off line.| 18 | |[backbat2.bat](/files/backbat2.bat)|Backup batch files (Windows 95/98/ME version)| 19 | ||usage: backbat backupdir| 20 | ||where: backupdir is the directory to copy batch files all batch files in the current directory will be backed up| 21 | ||Make sure that there is at least one argument. Save the backup directory. Check to make sure that the backupdir exists and isn't a file| 22 | ||If the directory does not exist, create it. Because we can't reliably check the errorlevel in Windows 95/98/ME, check if the directory exists after we do the make directory command. Copy each batch file one at a time. Note: the for loop variable (%%b) must be contain only one letter. Use the for loop again to check if each file was copied (since it is difficult to run multiple commands in a for loop).| 23 | ||Clean up: unset our variable.| 24 | |[badpath.bat](/files/badpath.bat)|This batch file will mess up your command prompt's PATH setting. Without setlocal and endlocal, set-ting variables changes the DOS environment.| 25 | |[copies.bat](/files/copies.bat)|Check various error levels by running copy commands.| 26 | |[cp.bat](/files/cp.bat)|Copy a file to a new directory, then make it read-only, then try the copy again. The second copy should fail and errorlevel will be set to a non-zero value.| 27 | |[cp2.bat](/files/cp2.bat)|Partial solution to Lab #2.| 28 | |[endless.bat](/files/endless.bat)|Endless loop -- use Ctrl+Break or Ctrl+C to stop it.| 29 | |[exist.bat](/files/exist.bat)|Check for existence of a file (testfile) and directory (testdir).| 30 | ||Note: this doesn't seem to work on Microsoft Networking network drives (such as W: in L-17).| 31 | ||testfile is a file| 32 | ||testdir is NOT a file| 33 | ||testfile is NOT a directory| 34 | ||testdir is a directory| 35 | |[go.bat](/files/go.bat)|An infinite loop -- use Ctrl+Break or Ctrl+C to stop it.| 36 | |[go2.bat](/files/go2.bat)|A conditional loop -- continues until no more arguments are left on the command line.| 37 | |[hello.bat](/files/hello.bat)|Hello world program.| 38 | |[keep.bat](/files/keep.bat)|Save the first parameter in the saved variable.| 39 | ||The shift command moves the %1 to %0 and %2 to %1, so that the previous value is replaced.| 40 | ||If we do another shift, the original %1 (now %0) gets lost.| 41 | ||Since we stored in the saved variable, we can recover the value. With named (as opposed to numbered) variables, you have to use a percent sign before and after the variable name to get the value.| 42 | |[main1.bat](/files/main1.bat)|Demonstrate call command to execute another batch file (sub).| 43 | |[main2.bat](/files/main2.bat)|Demonstrate call with setting variables and passing parameters.| 44 | |[mbcopy.bat](/files/mbcopy.bat)|One possible solution to Lab #2, Part B.| 45 | ||MBCOPY.BAT copies any number of files or directories to to a directory. The command uses the following syntax:| 46 | ||mbcopy dest src1 src2 ...| 47 | ||If the destination directory does not exist, create it| 48 | ||If the source file is a directory, it gets copied differently from an ordinary file.| 49 | ||If the source directory does not already exist in the destination directory, create it so that XCOPY does not prompt the user.| 50 | |[mycopy.bat](/files/mycopy.bat)|MYCOPY.BAT copies any number of files to a directory. The command uses the following syntax:| 51 | ||mycopy dir file1 file2 ...| 52 | |[myvar.bat](/files/myvar.bat)|Set a variable which will remain in the DOS environment after the batch file is completed. To verify this, enter set at the DOS prompt after you run this batch file.| 53 | |[myvar2.bat](/files/myvar2.bat)|Set a variable which will not affect the DOS environment after the batch file is completed. To verify this, enter set at the DOS prompt after you run this batch file. Combine this and myvar.bat to see what happens. Note: Windows NT or 2000 only.| 54 | |[p.bat](/files/p.bat)|Set the PATH on the network in L-17.| 55 | |[param.bat](/files/param.bat)|You can access up to nine command-line parameters at any given time.| 56 | |[param2.bat](/files/param2.bat)|You can access up to nine command-line parameters at any given time, but you can choose to access only selected parameters, and ignore the rest.| 57 | |[param3.bat](/files/param3.bat)|The shift command can be used to process each command-line parameter, one at a time, using the %1 variable.| 58 | |[param4.bat](/files/param4.bat)|shift can be used when you need to process more than nine parameters.| 59 | |[param5.bat](/files/param5.bat)|shift can be used when you need to process more than nine parameters; you can still access only nine at a time.| 60 | |[rems.bat](/files/rems.bat)|This is a comment.| 61 | |[rems2.bat](/files/rems2.bat)|More comments.| 62 | |[Remove_Cbs_Logs.bat](/files/Remove_Cbs_Logs.bat)|This is caused by Windows Resource Protection (WRP), which stops programs overwriting essential system files. It keeps its log files in C:\Windows\Logs\CBS. The SFC.exe program writes the details of each verification operation and of each repair operation to the CBS.log file. The CBS.persist.log is generated when the CBS gets to be around 50Mb in size. CBS.log is copied to cbs.persist.log and a new cbs.log file is started. The cbs logs would only be useful for serious troubleshooting issues. If the system is running fine, we can delete this file and SFC.exe will create a new one the next time it is run. So why do we have this mysterious process writing a files in the temp folder?? It appears that on a number of servers we can see the SFC archive process has failed to recycle properly and as a result had been running for a long time.| 63 | |[safepath.bat](/files/safepath.bat)|This batch file will not affect the DOS PATH. Note: Windows NT or 2000 only.| 64 | |[safepath9x.bat](/files/safepath9x.bat)|This batch file will not affect the DOS PATH, by making a copy of the PATH variable beforehand, and restoring it at the end of the batch file.| 65 | |[shift.bat](/files/shift.bat)|Demonstrate shift command.| 66 | |[shifter.bat](/files/shifter.bat)|Demonstrate shift command (no echo).| 67 | |[str1.bat](/files/str1.bat)|This demonstrates the form of the if command comparing strings. If you run this batch file without any parameters, you will get an error message.| 68 | |[str2.bat](/files/str2.bat)|This demonstrates the correct form of the if command for comparing strings. If you run this batch file without any parameters, you will not get an error message, because the empty quotes will be on both the left side and on the right side. In the previous batch file (str1.bat) the left side would be blank, causing an error.| 69 | |[str3.bat](/files/str3.bat)|The alternative form of string comparison. In this case, the dot takes up space on the left side if no parameter is given.| 70 | |[sub.bat](/files/sub.bat)|This is the batch file called by both main1.bat and main2.bat. It demonstrates the use of shared variables and parameters passed by the call command.| 71 | |[tf1.bat](/files/tf1.bat)|Demonstrates incorrect if command. If true, goto end. Otherwise, both echo statements are executed.| 72 | |[tf2.bat](/files/tf2.bat)|Demonstrates correct if command. If true, only one echo statement is shown. If false, only one echo statement is is also shown, because the following goto skips over the second (true case) echo command.| 73 | |[tf3.bat](/files/tf3.bat)|Negative form of if command. Here, the not keyword is used to goto the false case; otherwise, the true case is executed immediately following the if. Then we skip over the false case with a second goto.| 74 | |[tf4.bat](/files/tf4.bat)|Demonstates a if-else condition. If the first if is true, then we go to the first case. If the first if is false, then we check the second if. If that if is true, then we go to the second case. If both ifs are false, the else case is executed.| 75 | |[tf5.bat](/files/tf5.bat)|Alternate form of if-elseif-else structure with goto for else case. That way, you can group code together in a more logical or more natural manner.| 76 | |[tf6.bat](/files/tf6.bat)|Demonstrates a logical OR condition. Both if commands goto the same label if true. Otherwise, both are false.| 77 | |[zero.bat](/files/zero.bat)|Batch file command line is copied to %0.| 78 | -------------------------------------------------------------------------------- /files/ApplicationInstall.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM 4 | REM |-------------------------------------------------------------------------------------------------------------------- 5 | REM | Purpose: Install for application 6 | REM | 7 | REM | Ver. Date Author Details 8 | REM | 1.00 22 MAY 2008 Anthony Duguid Initial version. 9 | REM |--------------------------------------------------------------------------------------------------------------------*/ 10 | 11 | 12 | REM 13 | REM /E = Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T. 14 | REM /D:m-d-y = Copies files changed on or after the specified date. 15 | REM If no date is given, copies only those files whose source time is newer than the destination time. 16 | REM /K = Copies attributes. Normal Xcopy will reset read-only attributes. 17 | REM /Q = Does not display file names while copying. 18 | REM /R = Overwrites read-only files. 19 | REM /Y = Suppresses prompting to confirm you want to overwrite an existing destination file. 20 | REM 21 | NET USE s: \\servername\sharedfolder$ 22 | REM Copy the install directory and sub-directories 23 | XCOPY "S:\App\*.*" "C:\Local\App\*.*" /E /K /Q /R /Y /D 24 | 25 | 26 | REM create the shortcuts 27 | COPY "s:\App\ShortcutLink.lnk" "%ALLUSERSPROFILE%\Desktop" 28 | 29 | 30 | REM Register the direct link libraries 31 | REGSVR32 /s "C:\Local\App\Library1.dll" 32 | REGSVR32 /s "C:\Local\App\Library2.dll" 33 | REGSVR32 /s "C:\Local\App\Library3.dll" 34 | REGSVR32 /s "C:\Local\App\Library4.dll" 35 | 36 | 37 | REM start application 38 | start "" "C:\Local\App\App.exe" "Application Name Here" 39 | -------------------------------------------------------------------------------- /files/BOOTDISK.BAT: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set DefFloppyDrive1=A: 4 | set DefFloppyDrive1_L=a: 5 | set DefFloppyDrive2=B: 6 | set DefFloppyDrive2_L=b: 7 | 8 | set DefFloppyDrive=%1 9 | 10 | cls 11 | 12 | :CHECK 13 | if not exist EBD\NUL goto NODIR 14 | 15 | if "%1"=="/?" GOTO USAGE 16 | 17 | if "%1"=="%DefFloppyDrive1%" goto FORMAT 18 | 19 | if "%1"=="%DefFloppyDrive1_L%" goto FORMAT 20 | 21 | if "%1"=="%DefFloppyDrive2%" goto FORMAT 22 | 23 | if "%1"=="%DefFloppyDrive2_L%" goto FORMAT 24 | 25 | :SET_FLOPPY 26 | echo Please specify the drive letter of your floppy drive. 27 | echo Press 1 for %DefFloppyDrive1% 28 | echo or 29 | echo Press 2 for %DefFloppyDrive2% 30 | echo. 31 | choice /c:12 Choose an option 32 | if errorlevel 2 goto BDRIVE 33 | if errorlevel 1 goto ADRIVE 34 | 35 | :ADRIVE 36 | set DefFloppyDrive=%DefFloppyDrive1% 37 | goto FORMAT 38 | 39 | :BDRIVE 40 | set DefFloppyDrive=%DefFloppyDrive2% 41 | goto FORMAT 42 | 43 | 44 | :FORMAT 45 | echo. 46 | echo To make a Startup Disk 47 | echo Label a disk "Windows 98 Startup Disk" and insert it into drive %DefFloppyDrive% 48 | echo Caution: Setup will delete any existing files on this floppy disk. 49 | echo. 50 | pause 51 | format %DefFloppyDrive% /u /v:EBD /autotest 52 | if not errorlevel 0 goto FORMAT_ERROR 53 | 54 | :COPY 55 | echo. 56 | echo Copying files to %DefFloppyDrive% ... 57 | copy .\EBD\*.* %DefFloppyDrive% > NUL 58 | echo. 59 | echo Transfering system files... 60 | sys %DefFloppyDrive% > NUL 61 | echo. 62 | echo Startup disk is ready. 63 | echo. 64 | goto END 65 | 66 | :FORMAT_ERROR 67 | echo. 68 | echo There was a error formatting the specified drive. 69 | echo Press Y to retry or N to cancel 70 | choice /c:yn 71 | if errorlevel 2 goto FORMAT_CANCEL 72 | if errorlevel 1 goto FORMAT 73 | :FORMAT_CANCEL 74 | echo . 75 | echo Exiting 76 | goto END 77 | 78 | :USAGE 79 | echo. 80 | echo Usage: bootdisk [drive letter:] 81 | echo e.g: bootdisk 82 | echo or 83 | echo bootdisk %DefFloppyDrive1% 84 | echo. 85 | echo This command should be run from the WINDOWS\COMMAND directory. 86 | echo. 87 | goto END 88 | 89 | :NODIR 90 | echo. 91 | echo The EBD directory does not exist. 92 | echo Change to the WINDOWS\COMMAND directory and try again. 93 | echo. 94 | goto END 95 | 96 | :END 97 | set DefFloppyDrive= 98 | set DefFloppyDrive1= 99 | set DefFloppyDrive1_L= 100 | set DefFloppyDrive2= 101 | set DefFloppyDrive2_L= 102 | -------------------------------------------------------------------------------- /files/DOSSTART.BAT: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Notes: 4 | REM DOSSTART.BAT is run whenenver you choose "Restart the computer 5 | REM in MS-DOS mode" from the Shutdown menu in Windows. It allows 6 | REM you to load programs that you might not want loaded in Windows, 7 | REM (because they have functional equivalents) but that you do 8 | REM want loaded under MS-DOS. The two primary candidates for 9 | REM this are MSCDEX and a real mode driver for the mouse you ship 10 | REM with your system. Commands that you want present in both Windows 11 | REM and MS-DOS should be placed in the Autoexec.bat in the 12 | REM \Image directory of your reference server. Please note that for 13 | REM MSCDEX you will need to load the corresponding real-mode CD 14 | REM driver in Config.sys. This driver won't be used by Windows 98 15 | REM but will be available prior to and after Windows 98 exits. 16 | REM 17 | REM This file is also helpful if you want to F8 boot into MS-DOS 7.0 18 | REM before Windows loads and access the CD-ROM. All you have to do 19 | REM is press F8 and then run DOSSTART to load MSCDEX and your real 20 | REM mode mouse driver (no need to remember the command line parameters 21 | REM for these two files. 22 | REM 23 | REM - You MUST explicitly specify the CD ROM Drive Letter for MSCDEX. 24 | REM - The string following the /D: statement must explicitly match 25 | REM the string in CONFIG.SYS following your CD-ROM device driver. 26 | 27 | REM MSCDEX.EXE /D:OEMCD001 /l:d 28 | REM MOUSE.EXE 29 | 30 | -------------------------------------------------------------------------------- /files/FCOUNT.BAT: -------------------------------------------------------------------------------- 1 | @echo off 2 | prep /om /fc %1.exe 3 | if errorlevel 1 goto done 4 | profile %1 %2 %3 %4 %5 %6 %7 %8 %9 5 | if errorlevel 1 goto done 6 | prep /m %1 7 | if errorlevel 1 goto done 8 | plist %1 9 | :done 10 | -------------------------------------------------------------------------------- /files/FCOVER.BAT: -------------------------------------------------------------------------------- 1 | @echo off 2 | prep /om /fv %1.exe 3 | if errorlevel 1 goto done 4 | profile %1 %2 %3 %4 %5 %6 %7 %8 %9 5 | if errorlevel 1 goto done 6 | prep /m %1 7 | if errorlevel 1 goto done 8 | plist %1 9 | :done 10 | -------------------------------------------------------------------------------- /files/FTIME.BAT: -------------------------------------------------------------------------------- 1 | @echo off 2 | prep /om /ft %1.exe 3 | if errorlevel 1 goto done 4 | profile %1 %2 %3 %4 %5 %6 %7 %8 %9 5 | if errorlevel 1 goto done 6 | prep /m %1 7 | if errorlevel 1 goto done 8 | plist %1 9 | :done 10 | -------------------------------------------------------------------------------- /files/LCOUNT.BAT: -------------------------------------------------------------------------------- 1 | rem This batch file must be invoked from the directory containing the exe to be profiled. If used from the IDE, do not change directories before running as a custom batch file. 2 | 3 | @echo off 4 | prep /om /lc %1.exe 5 | if errorlevel 1 goto done 6 | profile %1 %2 %3 %4 %5 %6 %7 %8 %9 7 | if errorlevel 1 goto done 8 | prep /m %1 9 | if errorlevel 1 goto done 10 | plist %1 11 | :done 12 | -------------------------------------------------------------------------------- /files/LCOVER.BAT: -------------------------------------------------------------------------------- 1 | rem This batch file must be invoked from the directory containing the exe to be profiled. If used from the IDE, do not change directories before running as a custom batch file. 2 | 3 | rem Line count profiling takes more time than other modes. See Help about limiting the scope of profiling if profiling a large application. 4 | 5 | @rem off 6 | prep /om /lv %1.exe 7 | if errorlevel 1 goto done 8 | profile %1 %2 %3 %4 %5 %6 %7 %8 %9 9 | if errorlevel 1 goto done 10 | prep /m %1 11 | if errorlevel 1 goto done 12 | plist %1 13 | :done 14 | -------------------------------------------------------------------------------- /files/MAKAPT15.BAT: -------------------------------------------------------------------------------- 1 | regedit /s adoapt15.reg 2 | -------------------------------------------------------------------------------- /files/MAKFRE15.BAT: -------------------------------------------------------------------------------- 1 | regedit /s adofre15.reg 2 | -------------------------------------------------------------------------------- /files/PINGNAME.BAT: -------------------------------------------------------------------------------- 1 | ping www.microsoft.com 2 | ping ftp.microsoft.com 3 | @echo off 4 | echo ... 5 | echo Click the Help window to continue with the Internet troubleshooter. 6 | -------------------------------------------------------------------------------- /files/PINGNUM.BAT: -------------------------------------------------------------------------------- 1 | ping 198.105.232.1 2 | ping 198.105.232.6 3 | @echo off 4 | echo ... 5 | echo Click the Help window to continue with the Internet troubleshooter. 6 | -------------------------------------------------------------------------------- /files/Remove_Cbs_Logs.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM 4 | REM |-------------------------------------------------------------------------------------------------------------------- 5 | REM | Purpose: This is caused by Windows Resource Protection (WRP), which stops programs overwriting essential system files. 6 | REM | It keeps its log files in C:\Windows\Logs\CBS. The SFC.exe program writes the details of each verification operation 7 | REM | and of each repair operation to the CBS.log file. The CBS.persist.log is generated when the CBS gets to be around 50Mb in size. 8 | REM | CBS.log is copied to cbs.persist.log and a new cbs.log file is started. The cbs logs would only be useful for serious troubleshooting issues. 9 | REM | If the system is running fine, we can delete this file and SFC.exe will create a new one the next time it is run. 10 | REM | 11 | REM | So why do we have this mysterious process writing a files in the temp folder?? It appears that on a number of servers 12 | REM | we can see the SFC archive process has failed to recycle properly and as a result had been running for a long time. 13 | REM | 14 | REM | Ver. Date Author Details 15 | REM | 1.00 13-DEC-2016 Anthony Duguid Initial version. 16 | REM |--------------------------------------------------------------------------------------------------------------------*/ 17 | 18 | 19 | SETLOCAL 20 | set CBS_LOG_FILES=%windir%\Logs\CBS\CbsPersist_*.log 21 | set CBS_CAB_FILES=%windir%\temp\cab_* 22 | set LOGFILE=C:\temp\delete_cbspersist_%USERNAME%_%date:~10,4%%date:~7,2%%date:~4,2%_%time:~0,2%%time:~3,2%_%time:~6,5% 23 | 24 | REM Removes the oversize CBS persist logs 25 | "cmd /c del /q %CBS_LOG_FILES% && echo %CBS_LOG_FILES%>>%LOGFILE%.log || echo %CBS_LOG_FILES%>>%LOGFILE%.err" 26 | 27 | REM Removes the duplicate failed cab_ files from Windows\temp. 28 | "cmd /c del /q %CBS_CAB_FILES% && echo %CBS_CAB_FILES%>>%LOGFILE%.log || echo %CBS_CAB_FILES%>>%LOGFILE%.err" 29 | -------------------------------------------------------------------------------- /files/SETUPNM.BAT: -------------------------------------------------------------------------------- 1 | set SETUP=setup 2 | -------------------------------------------------------------------------------- /files/Start17.bat: -------------------------------------------------------------------------------- 1 | @\\nctr3\netlogon\start17.bat 2 | 3 | -------------------------------------------------------------------------------- /files/VCVARS32.BAT: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem 3 | rem Root of Visual Developer Studio Common files. 4 | set VSCommonDir=C:\PROGRA~1\MICROS~1\COMMON 5 | 6 | rem 7 | rem Root of Visual Developer Studio installed files. 8 | rem 9 | set MSDevDir=C:\PROGRA~1\MICROS~1\COMMON\msdev98 10 | 11 | rem 12 | rem Root of Visual C++ installed files. 13 | rem 14 | set MSVCDir=C:\PROGRA~1\MICROS~1\VC98 15 | 16 | rem 17 | rem VcOsDir is used to help create either a Windows 95 or Windows NT specific path. 18 | rem 19 | set VcOsDir=WIN95 20 | if "%OS%" == "Windows_NT" set VcOsDir=WINNT 21 | 22 | rem 23 | echo Setting environment for using Microsoft Visual C++ tools. 24 | rem 25 | 26 | if "%OS%" == "Windows_NT" set PATH=%MSDevDir%\BIN;%MSVCDir%\BIN;%VSCommonDir%\TOOLS\%VcOsDir%;%VSCommonDir%\TOOLS;%PATH% 27 | if "%OS%" == "" set PATH="%MSDevDir%\BIN";"%MSVCDir%\BIN";"%VSCommonDir%\TOOLS\%VcOsDir%";"%VSCommonDir%\TOOLS";"%windir%\SYSTEM";"%PATH%" 28 | set INCLUDE=%MSVCDir%\ATL\INCLUDE;%MSVCDir%\INCLUDE;%MSVCDir%\MFC\INCLUDE;%INCLUDE% 29 | set LIB=%MSVCDir%\LIB;%MSVCDir%\MFC\LIB;%LIB% 30 | 31 | set VcOsDir= 32 | set VSCommonDir= 33 | 34 | -------------------------------------------------------------------------------- /files/args.bat: -------------------------------------------------------------------------------- 1 | rem Display the use of spaces with echo 2 | 3 | echo %1%2%3 %4%5%6 %7%8 %9 4 | 5 | -------------------------------------------------------------------------------- /files/autoexec.bat: -------------------------------------------------------------------------------- 1 | REM [Header] 2 | @ECHO OFF 3 | if not exist \newname.reg call newname.bat 4 | if not exist \runonce.reg regedit \newname.reg 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /files/backbat.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem 3 | rem backbat.bat -- Backup batch files (Windows NT/2000 version) 4 | rem 5 | rem usage: backbat backupdir 6 | rem where: backupdir is the directory to copy batch files 7 | rem all batch files in the current directory will 8 | rem be backed up 9 | rem 10 | 11 | rem Make sure that there is at least one argument 12 | 13 | if not "%1"=="" goto argsok 14 | 15 | echo usage: %0 backupdir 16 | echo where: backupdir is the directory to copy batch files 17 | echo all batch files in the current directory will 18 | echo be backed up 19 | 20 | goto end 21 | 22 | 23 | :argsok 24 | 25 | 26 | setlocal 27 | 28 | 29 | rem Save the backup directory 30 | 31 | set backupdir=%1 32 | 33 | 34 | rem Check to make sure that the backupdir exists and isn't a file 35 | 36 | if not exist %backupdir% goto notfile 37 | 38 | echo %backupdir% is a file 39 | goto end 40 | 41 | 42 | :notfile 43 | 44 | rem If the directory does not exist, create it. 45 | 46 | if exist %backupdir%\nul goto skipdir 47 | 48 | md %backupdir% 49 | if "%errorlevel%"=="0" goto skipdir 50 | 51 | echo Error creating backup directory 52 | goto end 53 | 54 | 55 | :skipdir 56 | 57 | rem Copy each batch file one at a time. 58 | rem Note: the for loop variable (%%b) must be contain only one letter. 59 | 60 | for %%b in ( *.bat ) do copy %%b %backupdir% > nul 61 | 62 | 63 | rem Use the for loop again to check if each file was copied (since it is 64 | rem difficult to run multiple commands in a for loop). 65 | 66 | for %%b in ( *.bat ) do if not exist %backupdir%\%%b echo %%b was not copied 67 | 68 | :end 69 | 70 | rem Clean up 71 | 72 | endlocal 73 | 74 | -------------------------------------------------------------------------------- /files/backbat2.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem 3 | rem backbat.bat -- Backup batch files (Windows 95/98/ME version) 4 | rem 5 | rem usage: backbat backupdir 6 | rem where: backupdir is the directory to copy batch files 7 | rem all batch files in the current directory will 8 | rem be backed up 9 | rem 10 | 11 | rem Make sure that there is at least one argument 12 | 13 | if not "%1"=="" goto argsok 14 | 15 | echo usage: %0 backupdir 16 | echo where: backupdir is the directory to copy batch files 17 | echo all batch files in the current directory will 18 | echo be backed up 19 | 20 | goto end 21 | 22 | 23 | :argsok 24 | 25 | rem Save the backup directory 26 | 27 | set backupdir=%1 28 | 29 | 30 | rem Check to make sure that the backupdir exists and isn't a file 31 | 32 | if not exist %backupdir% goto notfile 33 | 34 | echo %backupdir% is a file 35 | goto end 36 | 37 | 38 | :notfile 39 | 40 | rem If the directory does not exist, create it. Because we can't reliably 41 | rem check the errorlevel in Windows 95/98/ME, check if the directory exists 42 | rem after we do the make directory command. 43 | 44 | if exist %backupdir%\nul goto skipdir 45 | 46 | md %backupdir% 47 | 48 | if exist %backupdir%\nul goto skipdir 49 | 50 | echo Error creating backup directory 51 | goto end 52 | 53 | 54 | :skipdir 55 | 56 | rem Copy each batch file one at a time by calling our subroutine. 57 | rem Note: the for loop variable (%%b) must be contain only one letter. 58 | 59 | for %%b in ( *.bat ) do copy %%b %backupdir% > nul 60 | 61 | :end 62 | 63 | rem Clean up: unset our variable 64 | 65 | set backupdir= 66 | 67 | -------------------------------------------------------------------------------- /files/badpath.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem This batch file will mess up your command prompt's PATH setting. Without 4 | rem setlocal and endlocal, set-ting variables changes the DOS environment. 5 | 6 | set path=abc 7 | -------------------------------------------------------------------------------- /files/copies.bat: -------------------------------------------------------------------------------- 1 | rem @echo off 2 | 3 | rem Check various error levels by running copy commands 4 | 5 | rem This should always work 6 | 7 | copy c:\autoexec.bat . 8 | if not errorlevel 0 echo error %errorlevel% 9 | pause 10 | 11 | 12 | rem Attempt to copy a non-existent file 13 | rem to an existing directory 14 | 15 | copy c:\xxxxxxxx.yyy . 16 | if not errorlevel 0 echo error %errorlevel% 17 | pause 18 | 19 | 20 | rem Attempt to copy an existing file to a 21 | rem non-existent directory 22 | 23 | copy c:\autoexec.bat q:\xyxyx\xyxyxy 24 | if not errorlevel 0 echo error %errorlevel% 25 | pause 26 | 27 | 28 | rem Attempt to copy over a read-only file 29 | 30 | attrib +r autoexec.bat 31 | 32 | copy c:\autoexec.bat . 33 | if not errorlevel 0 echo error %errorlevel% 34 | pause 35 | 36 | -------------------------------------------------------------------------------- /files/cp.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem Copy a file to a new directory, then make it read-only, 3 | rem then try the copy again. The second copy should fail 4 | rem and errorlevel will be set to a non-zero value. 5 | rem 6 | 7 | md %1 8 | echo %errorlevel% 9 | copy %2 %1 10 | echo %errorlevel% 11 | cd %1 12 | attrib +r %2 13 | echo %errorlevel% 14 | cd .. 15 | copy %2 %1 16 | echo %errorlevel% 17 | 18 | -------------------------------------------------------------------------------- /files/cp2.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem Partial solution to Lab #2 3 | rem 4 | 5 | rem 6 | rem We can comment out the first "if" because if %2 is set, then 7 | rem %1 *must* be set 8 | rem 9 | 10 | rem if .%1 == . goto missing 11 | 12 | rem 13 | rem If the "if" condition evaluates to true, then the "goto missing" 14 | rem command is executed. The dots are used to prevent an error 15 | rem message in case the user doesn't provide at least two 16 | rem command-line arguments. The false case begins on the next 17 | rem line. 18 | rem 19 | 20 | if .%2 == . goto missing 21 | goto start 22 | 23 | :missing 24 | echo usage: %0 dir file 25 | goto end 26 | 27 | :start 28 | if not exist %1 goto checkdir 29 | echo %1 is a file, not a directory 30 | goto end 31 | 32 | :checkdir 33 | 34 | rem 35 | rem This "if" is used to check for the existence of a directory. 36 | rem The \nul must be used, because you can only check for the 37 | rem existence of files. "nul" is a special file that exists 38 | rem in every directory. 39 | rem 40 | 41 | if exist %1\nul goto docopy 42 | md %1 > nul 43 | if errorlevel 0 goto docopy 44 | echo Cannot create directory %1 45 | goto end 46 | 47 | :docopy 48 | copy %2 %1 > nul 49 | if errorlevel 0 goto end 50 | echo Cannot copy file %1 to directory %2 51 | 52 | :end 53 | -------------------------------------------------------------------------------- /files/exist.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem Check for existence of a file and directory 4 | rem Note: this doesn't seem to work on Microsoft Networking network drives 5 | rem 6 | 7 | Create a file and a directory 8 | 9 | echo > testfile 10 | md testdir 11 | 12 | 13 | rem testfile is a file 14 | rem testdir is NOT a file 15 | 16 | if exist testfile echo testfile is a file 17 | if exist testdir echo testdir is a file 18 | 19 | rem testfile is NOT a directory 20 | rem testdir is a directory 21 | 22 | if exist testfile\nul echo testfile is a directory 23 | if exist testdir\nul echo testdir is a directory 24 | 25 | rem testfile is a file 26 | rem testdir is NOT a file 27 | 28 | if not exist testfile echo testfile is not a file 29 | if not exist testdir echo testdir is not a file 30 | 31 | rem testfile is NOT a directory 32 | rem testdir is a directory 33 | 34 | if not exist testfile\nul echo testfile is not a directory 35 | if not exist testdir\nul echo testdir is not a directory 36 | 37 | 38 | echo Cleaning up 39 | 40 | rem 41 | rem Now remove both the file and the directory 42 | rem 43 | 44 | del testfile 45 | rd testdir 46 | 47 | rem testfile is no longer a file 48 | rem testdir was never a file to begin with 49 | 50 | if exist testfile echo testfile is a file 51 | if exist testdir echo testdir is a file 52 | 53 | rem testfile was never a directory to begin with 54 | rem testdir is no longer a directory 55 | 56 | if exist testfile\nul echo testfile is a directory 57 | if exist testdir\nul echo testdir is a directory 58 | 59 | rem testfile is no longer a file 60 | rem testdir was never a file to begin with 61 | 62 | if not exist testfile echo testfile is not a file 63 | if not exist testdir echo testdir is not a file 64 | 65 | rem testfile was never a directory to begin with 66 | rem testdir is no longer a directory 67 | 68 | if not exist testfile\nul echo testfile is not a directory 69 | if not exist testdir\nul echo testdir is not a directory 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /files/go.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem An infinite loop -- press Ctrl-C or Ctrl-Break to stop it 4 | 5 | :endless 6 | echo Somebody stop this thing! 7 | goto endless 8 | -------------------------------------------------------------------------------- /files/go2.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem A conditional loop -- continues until no more arguments are left 4 | rem on the command line 5 | 6 | :start 7 | if "%1" == "" goto stop 8 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 9 | shift 10 | goto start 11 | :stop 12 | echo Done. 13 | -------------------------------------------------------------------------------- /files/hello.bat: -------------------------------------------------------------------------------- 1 | rem Hello world program 2 | 3 | echo Hello, Cruel World! 4 | -------------------------------------------------------------------------------- /files/keep.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem 4 | rem Save the first parameter in the saved variable 5 | rem 6 | 7 | set saved=%1 8 | 9 | echo parameter zero (batch file commandc) is %0 10 | echo first parameter is %1 11 | 12 | rem 13 | rem The shift command moves the %1 to %0 and %2 to %1, so that the 14 | rem previous value is replaced 15 | 16 | shift 17 | echo new first parameter is %1 18 | echo old first parameter is %0 19 | 20 | rem 21 | rem If we do another shift, the original %1 (now %0) gets lost. 22 | rem Since we stored in the saved variable, we can recover the 23 | rem value. With named (as opposed to numbered) variables, you 24 | rem have to use a percent sign before and after the variable 25 | rem name to get the value. 26 | rem 27 | 28 | shift 29 | echo new first parameter is %1 30 | echo original first parameter is %saved% 31 | echo now parameter zero is %0 32 | -------------------------------------------------------------------------------- /files/main1.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem Demonstrate call command to execute another batch file (sub) 3 | rem 4 | 5 | echo Starting %0 6 | echo Calling sub 7 | call sub 8 | echo sub returned 9 | echo Leaving %0 10 | -------------------------------------------------------------------------------- /files/main2.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem Demonstrate "call" with setting variables and passing parameters. 3 | rem 4 | 5 | echo Starting %0 6 | echo Calling sub 7 | set oldmydir=%mydir% 8 | set mydir=c:\comp863 9 | call sub %1 %2 %3 %4 %5 10 | echo sub returned, mylocal=%mydir% 11 | set mydir=%oldmydir% 12 | set oldmydir= 13 | echo Leaving %0 14 | -------------------------------------------------------------------------------- /files/mbcopy.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem 3 | rem MBCOPY.BAT 4 | rem Author: Mike Boldin, Niagara College 5 | rem 6 | rem Description: 7 | rem 8 | rem MBCOPY.BAT copies any number of files or directories to 9 | rem to a directory. 10 | rem 11 | rem The command uses the following syntax: 12 | rem mbcopy dest src1 src2 ... 13 | rem 14 | rem Modification History: 15 | rem 2000.09.15 Modified original MYCOPY.BAT for Lab #2 16 | rem 17 | rem 18 | 19 | if "%1"=="" goto usage 20 | if "%2"=="" goto usage 21 | if not "%1"=="/?" goto start 22 | 23 | :usage 24 | 25 | rem 26 | rem Show usage 27 | rem 28 | 29 | echo usage: %0 dest-dir src [...] 30 | echo where: dest-dir is the destination directory 31 | echo src is a file or directory to copy (multiple src 32 | echo files or directories may be specified) 33 | goto end 34 | 35 | :start 36 | 37 | setlocal 38 | set todir=%1 39 | 40 | rem 41 | rem If the destination directory does not exist, create it 42 | rem 43 | 44 | if exist %todir%\nul goto getfile 45 | 46 | echo Creating directory %todir% 47 | md %todir% 48 | 49 | if not errorlevel 1 goto getfile 50 | 51 | echo Error creating directory %todir% 52 | goto end 53 | 54 | :getfile 55 | 56 | shift 57 | 58 | if "%1"=="" goto endok 59 | 60 | rem 61 | rem If the source file is a directory, it gets copied differently 62 | rem from an ordinary file 63 | rem 64 | 65 | if exist %1\nul goto copydir1 66 | 67 | copy %1 %todir% > nul 68 | 69 | goto check 70 | 71 | :copydir1 72 | 73 | rem 74 | rem If the source directory does not already exist in the 75 | rem destination directory, create it so that XCOPY does not 76 | rem prompt the user 77 | rem 78 | 79 | if exist %todir%\%1 goto copydir2 80 | 81 | md %todir%\%1 82 | 83 | if not errorlevel 1 goto copydir2 84 | 85 | echo Error creating directory %todir%\%1 86 | goto end 87 | 88 | :copydir2 89 | 90 | xcopy %1 %todir%\%1 /s /e > nul 91 | 92 | :check 93 | 94 | if not errorlevel 1 goto getfile 95 | 96 | echo Error copying %1 97 | goto end 98 | 99 | goto getfile 100 | 101 | :endok 102 | 103 | echo All done 104 | 105 | :end 106 | 107 | endlocal 108 | -------------------------------------------------------------------------------- /files/mycopy.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem 3 | rem MYCOPY.BAT copies any number of files 4 | rem to a directory. 5 | rem 6 | rem The command uses the following syntax: 7 | rem mycopy dir file1 file2 ... 8 | rem 9 | 10 | set todir=%1 11 | 12 | :getfile 13 | shift 14 | 15 | if "%1"=="" goto end 16 | 17 | copy %1 %todir% 18 | 19 | goto getfile 20 | 21 | :end 22 | 23 | set todir= 24 | 25 | echo All done -------------------------------------------------------------------------------- /files/myvar.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem Set a variable which will remain in the DOS environment after the batch 4 | rem file is completed. To verify this, enter "set" at the DOS prompt after 5 | rem you run this batch file. 6 | 7 | set myvar=abc 8 | -------------------------------------------------------------------------------- /files/myvar2.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem Set a variable which will not affect the DOS environment after the batch 4 | rem file is completed. To verify this, enter "set" at the DOS prompt after 5 | rem you run this batch file. Combine this and myvar.bat to see what happens. 6 | rem 7 | rem Note: Windows NT or 2000 only 8 | 9 | echo Before setlocal, myvar is %myvar% 10 | 11 | setlocal 12 | 13 | set myvar=def 14 | 15 | echo After set, myvar is %myvar% 16 | 17 | endlocal 18 | 19 | echo After endlocal, myvar is %myvar% 20 | -------------------------------------------------------------------------------- /files/newname.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | goto first 3 | :loop 4 | echo The Computer number is invalid....Try again 5 | :First 6 | Choice Enter Row letter A,B,C,D or E /c:ABCDE 7 | if errorlevel 1 set row=A 8 | if errorlevel 2 set row=B 9 | if errorlevel 3 set row=C 10 | if errorlevel 4 set row=D 11 | if errorlevel 5 set row=E 12 | Choice Enter Computer Number 1,2,3,4 or 5 /c:12345 13 | if errorlevel 1 set comp=1 14 | if errorlevel 2 set comp=2 15 | if errorlevel 3 set comp=3 16 | if errorlevel 4 set comp=4 17 | if errorlevel 5 set comp=5 18 | if %row%==A if %comp%==2 goto loop 19 | if %row%==A if %comp%==5 goto loop 20 | if %row%==B if %comp%==5 goto loop 21 | if %row%==E if %comp%==4 goto loop 22 | if %row%==E if %comp%==5 goto loop 23 | echo the computer selected is %row%%comp% 24 | choice is this correct /c:YN 25 | if errorlevel 2 goto First 26 | 27 | rem Here to create a regestry file 28 | echo REGEDIT4>\newname.reg 29 | echo "">>\newname.reg 30 | echo [HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName]>>\newname.reg 31 | echo "ComputerName"="%row%%comp%L17">>\newname.reg 32 | echo "">>\newname.reg 33 | echo [HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\VNETSUP]>>\newname.reg 34 | echo "ComputerName"="%row%%comp%L17">>\newname.reg 35 | echo "Workgroup"="CIT_L17">>\newname.reg 36 | echo "Comment"="L17 System Unit %row%%comp%">>\newname.reg 37 | 38 | regedit \newname.reg -------------------------------------------------------------------------------- /files/p.bat: -------------------------------------------------------------------------------- 1 | PATH=D:\WINNT\system32;D:\WINNT;W:\MBOLDIN\BIN 2 | 3 | -------------------------------------------------------------------------------- /files/param.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem 4 | rem You can access up to nine command-line parameters at any given time. 5 | rem 6 | 7 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 8 | 9 | -------------------------------------------------------------------------------- /files/param2.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem 4 | rem You can access up to nine command-line parameters at any given time, 5 | rem but you can choose to access only selected parameters, and 6 | rem ignore the rest. 7 | rem 8 | 9 | echo %1 %3 %5 %7 %9 10 | 11 | -------------------------------------------------------------------------------- /files/param3.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem 4 | rem The shift command can be used to process each command-line 5 | rem parameter, one at a time, using the %1 variable. 6 | rem 7 | 8 | echo %1 9 | shift 10 | echo %1 11 | shift 12 | echo %1 13 | shift 14 | 15 | -------------------------------------------------------------------------------- /files/param4.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem 4 | rem shift can be used when you need to process more than nine 5 | rem parameters. 6 | rem 7 | 8 | echo %1 9 | shift 10 | echo %1 11 | shift 12 | echo %1 13 | shift 14 | echo %1 15 | shift 16 | echo %1 17 | shift 18 | echo %1 19 | shift 20 | echo %1 21 | shift 22 | echo %1 23 | shift 24 | echo %1 25 | shift 26 | echo %1 27 | shift 28 | echo %1 29 | shift 30 | 31 | 32 | -------------------------------------------------------------------------------- /files/param5.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem 4 | rem shift can be used when you need to process more than nine 5 | rem parameters; you can still access only nine at a time. 6 | rem 7 | 8 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 9 | shift 10 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 11 | shift 12 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 13 | shift 14 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 15 | shift 16 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 17 | shift 18 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 19 | shift 20 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 21 | shift 22 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 23 | shift 24 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 25 | shift 26 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 27 | shift 28 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 29 | shift 30 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 31 | shift 32 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 33 | shift 34 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 35 | shift 36 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 37 | shift 38 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 39 | shift 40 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 41 | shift 42 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 43 | shift 44 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 45 | shift 46 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 47 | shift 48 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 49 | shift 50 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 51 | shift 52 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 53 | shift 54 | 55 | 56 | -------------------------------------------------------------------------------- /files/rems.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem 3 | rem 4 | rem This is a comment 5 | rem 6 | rem 7 | rem 8 | -------------------------------------------------------------------------------- /files/rems2.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | : 3 | : 4 | : The colon can also be used for comments, but you need to be 5 | : careful, since colons are also used to begin goto labels. 6 | : 7 | : 8 | -------------------------------------------------------------------------------- /files/safepath.bat: -------------------------------------------------------------------------------- 1 | rem @echo off 2 | 3 | rem This batch file will not affect the DOS PATH. Windows NT or 2000 only. 4 | 5 | setlocal 6 | 7 | set path=abc 8 | 9 | endlocal 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /files/safepath9x.bat: -------------------------------------------------------------------------------- 1 | rem @echo off 2 | 3 | rem This batch file will not affect the DOS PATH, by making a copy of the PATH 4 | rem variable beforehand, and restoring it at the end of the batch file. 5 | 6 | echo Initially, PATH is %path% 7 | 8 | set oldpath=%path% 9 | 10 | set path=abc 11 | 12 | echo Now, PATH is %path% 13 | 14 | echo Old PATH is %oldpath% 15 | 16 | set path=%oldpath% 17 | 18 | echo Finally, PATH is %path% 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /files/shift.bat: -------------------------------------------------------------------------------- 1 | rem Demonstrate shift command 2 | 3 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 4 | shift 5 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 6 | shift 7 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 8 | shift 9 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 10 | shift 11 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 12 | 13 | 14 | -------------------------------------------------------------------------------- /files/shifter.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem Demonstrate shift command (no echo) 4 | 5 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 6 | shift 7 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 8 | shift 9 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 10 | shift 11 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 12 | shift 13 | echo %1 %2 %3 %4 %5 %6 %7 %8 %9 14 | 15 | 16 | -------------------------------------------------------------------------------- /files/str1.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem This demonstrates the form of the if command comparing strings 3 | rem If you run this batch file without any parameters, you will 4 | rem get an error message. 5 | rem 6 | 7 | if %1=="" goto end 8 | echo The first parameter is %1 9 | :end 10 | -------------------------------------------------------------------------------- /files/str2.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem This demonstrates the correct form of the if command for 3 | rem comparing strings. If you run this batch file without any 4 | rem parameters, you will not get an error message, because 5 | rem the empty quotes will be on both the left side and 6 | rem on the right side. In the previous batch file (str1.bat) 7 | rem the left side would be blank, causing an error. 8 | rem 9 | 10 | if "%1"=="" goto end 11 | echo The first parameter is %1 12 | :end -------------------------------------------------------------------------------- /files/str3.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem The alternative form of string comparison. In this case, 3 | rem the dot takes up space on the left side if no parameter 4 | rem is given. 5 | rem 6 | 7 | if .%1==. goto end 8 | echo The first parameter is %1 9 | :end 10 | -------------------------------------------------------------------------------- /files/sub.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem This is the batch file "called" by both main1.bat and main2.bat. 3 | rem It demonstrates the use of shared variables and parameters 4 | rem passed by the "call" command. 5 | rem 6 | 7 | echo Entering batch file %0 8 | echo Before setlocal, mydir=%mydir% 9 | set submydir=%mydir% 10 | set mydir=c:\ 11 | echo Now, mydir=%mydir% 12 | echo Got args %1 %2 %3 %4 %5 %6 %7 %8 %9 13 | dir /a:d 14 | set mydir=%submydir% 15 | set submydir= 16 | echo After endlocal, mydir=%mydir% 17 | echo Leaving batch file %0 18 | -------------------------------------------------------------------------------- /files/tf1.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem Demonstrates incorrect "if" command. If true, goto end. 3 | rem Otherwise, rem both echo statements are executed. 4 | rem 5 | 6 | if .%1==. goto end 7 | echo If is false 8 | :end 9 | echo If is true 10 | -------------------------------------------------------------------------------- /files/tf2.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem Demonstrates correct "if" command. If true, only one echo 3 | rem statement is shown. If false, only one echo statement is 4 | rem is also shown, because the following goto skips over the 5 | rem second (true case) echo command. 6 | rem 7 | 8 | if .%1==. goto iftrue 9 | echo If is false 10 | goto iffalse 11 | :iftrue 12 | echo If is true 13 | :iffalse 14 | 15 | -------------------------------------------------------------------------------- /files/tf3.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem Negative form of "if" command. Here, the "not" keyword is 3 | rem used to goto the false case; otherwise, the true case is 4 | rem executed immediately following the "if". Then we skip 5 | rem over the false case with a second goto. 6 | rem 7 | 8 | if not .%1 == . goto iffalse 9 | echo If is true 10 | goto iftrue 11 | :iffalse 12 | echo If is false 13 | :iftrue 14 | 15 | 16 | -------------------------------------------------------------------------------- /files/tf4.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem Demonstates a if-else if-else condition. If the first "if" is 3 | rem true, then we go to the first case (1). If the first "if" is 4 | rem false, then we check the second "if". If that "if" is true, 5 | rem then we go to the second case (2). If both "ifs" are false, 6 | rem the "else" case is executed. 7 | rem 8 | 9 | if .%1 == .1 goto 1 10 | if .%1 == .2 goto 2 11 | echo else (neither 1 nor 2) 12 | goto endif 13 | :1 14 | echo You selected 1 15 | goto endif 16 | :2 17 | echo You selected 2 18 | goto endif 19 | :endif 20 | -------------------------------------------------------------------------------- /files/tf5.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem Alternate form of if-elseif-else structure with goto for else 3 | rem case. That way, you can group code together in a "more logical" 4 | rem or "more natural" manner. 5 | rem 6 | 7 | if .%1 == .1 goto 1 8 | if .%1 == .2 goto 2 9 | goto else 10 | :1 11 | echo You selected 1 12 | goto endif 13 | :2 14 | echo You selected 2 15 | goto endif 16 | :else 17 | echo else (neither 1 nor 2) 18 | goto endif 19 | :endif 20 | 21 | -------------------------------------------------------------------------------- /files/tf6.bat: -------------------------------------------------------------------------------- 1 | rem 2 | rem Demonstrates a logical OR condition. Both "if" commands goto 3 | rem the same label if true. Otherwise, both are false. 4 | rem 5 | 6 | if .%1 == .1 goto valid 7 | if .%1 == .2 goto valid 8 | echo You selection is invalid 9 | goto end 10 | :valid 11 | echo You selected 1 or 2 12 | :end 13 | 14 | -------------------------------------------------------------------------------- /files/zero.bat: -------------------------------------------------------------------------------- 1 | rem Batch file command line is copied to %0 2 | 3 | echo %0 4 | --------------------------------------------------------------------------------