Saturday, September 17, 2011
set folder=Documents and Settings
for /F "tokens=1 usebackq delims==\ " %%i IN (`net view`) DO (
echo Start copying %%i...
start /wait /min /high robocopy.exe "\\%%i\C$" X:\backup\uim\%%i\C *.doc *.xls /S /R:1 /W:120 /XD RECYCLER batmail "Application Data" game* "Default User" "ÿáí½«¡δ" "Local Settings" windows winxp wxp w2k winnt "Program Files" Temp NetHood Recycled Install "The Bat!" "System Volume Information" readme /XF "~*.*" readme /XJ /XO
start /wait /min /high robocopy.exe "\\%%i\D$" X:\backup\uim\%%i\D *.doc *.xls /S /R:0 /W:1 /XD RECYCLER SCANJET batmail "Application Data" game* "Default User" "ÿáí½«¡δ" "Local Settings" Temp Recycled Install readme/XF "~*.*" "System Volume Information" readme /XJ /XO
Wednesday, September 14, 2011
A: Start Dr.Batcher and type the following script:
if "%~2"=="" goto error
if "%~1"=="" goto error
net user %~1 %~2 /add
echo Usage: %~0 user password
Friday, September 9, 2011
set "a=111 222 "
set /a n+=1
for /f "tokens=%n%" %%i in ("%a%") do (
if not "%%i"=="" set b=%b%%%i && goto:loop
Of course, you have to change this code a bit before using it. You can do it with the help of our award-winning batch files editor. Hope you'll find this example useful.
Sunday, August 28, 2011
There is a plenty (about 5 thousands) of files named the following way:
And the same amount of images in 'Screens' folder:
Alse there are Web pages in 'Html' folder:
Is it possible to write a batch script that creates folders named after a file and move there a file, a picture and a Web page? ZIP archive should be also extracted there.
The batch script to solve this task looks like this:
For %%A In (%ArcDir%\*.zip %ArcDir%\*.jar %ArcDir%\*.sys) Do (
md "%%~nA">Nul 2>&1
If /I "%%~xA"==".zip" (
pkzip -extr=up "%%A" "%OutDir%\%%~nA">Nul 2>&1
) Else (
Copy /y "%%A" "%OutDir%\%%~nA">Nul 2>&1
Copy /y "%ScreenDir%\%%~nA.*" "%OutDir%\%%~nA">Nul 2>&1
Copy /y "%HTMLDir%\%%~nA.html" "%OutDir%\%%~nA">Nul 2>&1
Hope you'll find this example useful. You can modify this script with the help of our batch files editor called Dr.Batcher.
Wednesday, August 24, 2011
start /wait "" "C:\Install\setup1.exe"
start /wait "" "C:\Install\setup2.exe"
start /wait "" "C:\Install\setup3.exe"
start /wait "" "C:\Install\setup4.exe"
start /wait "" "C:\Install\setup5.exe"
It is not hard to change the paths to the installation EXEs and their names. But to simplify the installation process you should search for command-line parameters of popular installation engines (InnoSetup, NSIS, Windows Installer etc.). These parameters should let you install software in 'silent' mode and specify destination folder, components to be installed and other settings.
Sunday, August 21, 2011
for %%i in (bmp jpg png gif) do (
forfiles -pC:\Test -s -m*.%%i -d+14 -c"cmd /c echo @PATH @FILE"
As far as you can see, this batch file searches for images in 'C:\Temp' folder, and shows those of them that were modified during the latest two weeks.
Hope you'll find this small example useful.
Monday, August 15, 2011
pushd "U:\Share Folder"
for /d %%i in (*) do (
rd /s /q "." 2>nul
Wednesday, August 10, 2011
This code will remove dots from the string with the current date. Can you consider the string that allows you to remove slashes?..
Monday, August 8, 2011
for %%i in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
for /f "tokens=*" %%a in ('dir /b /s /a-d %%i:\FileName.ext 2^>nul') do (
set "foundFile=%%a" & goto found
echo File not found
echo File found - %foundFile%
As far as you can see, we simply look through all letters for logical drives and then search for the needful file on the each drive separately.
Thursday, July 14, 2011
for %%i in (SourceDir\*) do (
if exist "DestDir\%%~nxi" (
mv "%%i" "DestDir\~%%~nxi"
) else (
mv "%%i" "DestDir"
Saturday, July 9, 2011
net use w: \\192.168.x.x\a1 > nul
echo "1. Disk connected"
copy w:\Prg.exe d:\123\Program\Prog.exe > nul
echo "2. File updated"
start d:\123\Program\Prog.exe > nul
echo "3. Run programm"
net use w: /delete > nul
echo "4. Disk disconnected"
You can change this batch file with help of our award-winning batch files editor. Hope you'll find this example useful.
Thursday, June 23, 2011
net use X: \\komp\updat pass /user:user /persistent:yes >Nul 2<&1
del /Q /F %dir%\*.*
PING 184.108.40.206 -n 1 -w 2000 2>NUL | FIND "TTL=" >NUL
copy /Y %od%\*.* %dir%
As far as you can see, first of all we check for existence of a virtual drive with the physical letter. If this drive doesn't exist, we create it. Finally we copy some files on it.
Tuesday, June 21, 2011
for /f "tokens=2*" %%i in ('reg query "hkcu\software\microsoft\windows\currentversion\explorer\shell folders" /v ;Startup ^|find /i "startup"') do @set "startfolder=%%j"
You can use this example to create scripts with the help of our powerful batch files editor. Hope you'll find this post useful.
Monday, June 13, 2011
/d[:mm-dd-yyyy] : Copies source files changed on or after the specified date only. If you do not include a mm-dd-yyyy value, xcopy copies all Source files that are newer than existing Destination files. This command-line option allows you to update files that have changed.
If you need to pass the current date to this command, you'll be surprised: on some configurations of the operating system %date% returns the current date in dd.mm.yyy format, while XCOPY requires mm-dd-yyyy. What to do? Here is some batch code that helps you to solve this problem:
xcopy c:\*.txt c:\temp /d:%mm%-%dd%-%yy%
Friday, June 10, 2011
if errorlevel 1 shutdown -r -f -t 0
As far as you can see, the way to check the connection is really simple: we just ping Mental Works Computing Software's site and reboot if it is not available. You can use Google or Yahoo! instead if you prefer.
Saturday, June 4, 2011
MOVE 1.ext ..\1.ext
Of course, the file to be moved and the batch script have to be placed in the same folder.
Sunday, May 29, 2011
So don't forget that Dr.Batcher lets you compile your batch scripts into Windows executables!
Tuesday, May 24, 2011
Don't forget to change the time and registry branch before using this solution. You can use our award-winning batch file editor to change this small script in according to your needs.
Sunday, May 22, 2011
Friday, May 20, 2011
for /l %%i in (1,1,255) do (
ping -n 1 192.168.1.%%i | findstr "TTL=" 1>nul && (
echo 192.168.1.%%i is UP
) || (
echo 192.168.1.%%i is DOWN
Tuesday, May 17, 2011
for /L %%i in (1, 1, 255) do ping 192.168.1.%%i
Of course, you have to use your own subnet mask instead of 192.168.1 in the example above. Hope this small script will help you to write your own powerful batch files.
Sunday, May 15, 2011
You can use this example in scripts that you create with help of our award-winning program designed to write batch files.
Friday, May 13, 2011
echo Thinking of a number...
if %nmb% GTR 10 goto rand
if %nmb% EQU 0 goto rand
echo Now you can try 3 times to guess the right one!
set /p "ent=Your number : "
set /a i=%i%+1
if %ent% EQU %nmb% (
echo You're lucky!
if %i% LSS 3 (
if %i% EQU 3 (
echo Game Over:(
Sunday, May 8, 2011
Sunday, May 1, 2011
if "%rand:~6%"=="" goto try
1>nul 2>&1 type prevrand.txt | find "%rand:~0,6%"
if not errorlevel 1 goto try
As far as you can see, we use a special text file to store all previously used numbers. Of course, it's better to remove it after you have done all the work, whatever you need to do with the generated numbers. Hope you'll find this small random numbers generator useful.
Tuesday, April 26, 2011
for /f %%i in ('dir /b') do (
ren "%%i" "!a1!-!a2!-!a3!_%%i"
If you run this script, you will see that it adds the date before the name of the file. It is not hard to modify the script to make it add the date to the end of batch file.
And here is also another version of this task's automation:
for /f %%i in ('dir /b') do (
ren "%file%" "%time:~0,2%-%time:~3,2%-%time:~6,2%_%file%"
Both of these scripts are quite quick, so in general you can use any of them.
Saturday, April 23, 2011
So what do you have to do? You can use a simple script like this:
@echo off for /f "tokens=1,2,3 delims=" %%a in ('dir /b *.*') do ren %%a[%%b]%%c %%a%%c
Hope you'll find it useful.
Wednesday, April 20, 2011
for /f "tokens=*" %%a in (first_file.txt) do (
if !count! GEQ !N! goto :EOF
set /a "count+=1"
But you can also try another version of this script. It will look like this (you should declare variables to run this script):
for /f "skip=2 tokens=*" %%a in (%file_name%) do (
set /a count=!count!+1
if /i !count! leq N echo %%a>>new.txt
Hope you'll find these scripts useful.
Tuesday, April 19, 2011
Sunday, April 17, 2011
The solution is really simple: you should just write 'echo Y |
Friday, April 15, 2011
Though our award-winning batch files editor Dr.Batcher allows you to create scripts very easy, it still doesn't let you just check a box to turn screen output off (we'll implement this feature one day, we promise). So you should use the following instruction:
ping 127.0.0.1 > nul
Of course, you can use any command you like, not only 'ping'. The main trick is '> nul'. It redirects the output from console to... nowhere! So you won't see anything except the command's name and given parameters themselves.
Tuesday, March 29, 2011
for /f "usebackq tokens=*" %%c in ("about.txt") do (
echo "%%c",>> about1.txt
As far as you can see, it's not difficult to write this script with help of our award-winning batch files editor. Hope you'll find this small example useful.
Friday, March 25, 2011
for %%i in (c:\DLL\ActiveX\*.ocx) do regsvr32 %%i
Please note that you can register even remote files
for %%i in (\\192.168.102.184\DLL\*.dll) do regsvr32 %%i
for %%i in (\\192.168.102.184\DLL\*.ocx) do regsvr32 %%i
Hope you'll find this example useful.
Wednesday, March 23, 2011
- tab-bar with bookmarks in professional mode;
- support for declining use of unnecessary list parameters in simple mode;
- support for viewing latest post from 'World of Batch Files' blog on start;
- 10 new examples;
- improved compatibility with Windows 7 64-bit;
- lots of bugfixes.
Friday, March 18, 2011
set /p password=Enter password:
for /f "tokens=*" %%i in ('in.com') do set "password=%%i"
echo The Password is:"%password%"
You can easily change this batch file with help of our award-winning tool Dr.Batcher. Hope you'll find both of them (script and tool) useful.
Monday, March 14, 2011
Tuesday, March 8, 2011
if condition goto :THEN
rem Something like ‘else’
rem Something like ‘then’
This is really different from the way of writing 'if' statements in C, Pascal, Java and even VBScript. Look at the modern batch script below. Does it look like C or Java code?
if condition (
) else (
It's not hard to use these constructions, simply don't forget to add 'setlocal enabledelayedexpansion' (without commas).
Friday, March 4, 2011
2) Switch to Simple mode;
3) Add a new command named "Start a Separate Command Promt" (START);
4) Change the value of parameter 'Command or program to start" to your URL surrounded with commas (for example, "http://www.drbatcher.com");
5) Set other needful parameters;
6) Add more URLs if necessary;
Wednesday, March 2, 2011
attrib +r *%date%*
del /q *.* 1>nul 2>&1
attrib -r *%date%*
Hope you'll find this simple code useful.
Thursday, February 24, 2011
if exist d: call :RSVI d
if exist x: call :RSVI x
if exist y: call :RSVI y
if exist z: call :RSVI z
rem Clear Recycler & System Volume Information
if exist %~1:\RECYCLER rd /s /q %~1:\RECYCLER
if exist "%~1:\System Volume Information" (
echo Y|cacls "%~1:\System Volume Information" /T /P "All":F /C
rd /s /q "%~1:\System Volume Information")
@del /f /s /q %TMP%\ >nul
@del /f /s /q %TEMP%\ >nul
@for /D %%f in ("%TMP%\*") do rd /q /s %%f >nul
@for /D %%f in ("%TEMP%\*") do rd /q /s %%f >nul
set folder=C:\Documents and Settings\
for /F "DELIMS=" %%f in ('dir "%folder%"') do (
echo ======================= "%%f" ======================== >> c:\deltemp.log
call :EXIST_SUB "%%f"
@if exist "%folder%%~1\Local Settings\Temp" call :RM_SUB "%folder%%~1\Local Settings\Temp" >nul
@if exist "%folder%%~1\Local Settings\History" call :RM_SUB "%folder%%~1\Local Settings\History" >nul
@if exist "%folder%%~1\Local Settings\Temporary Internet Files" call :RM_SUB "%folder%%~1\Local Settings\Temporary Internet Files" >nul
@if exist "%folder%%~1\NetHood" call :RM_SUB "%folder%%~1\NetHood" >nul
@if exist "%folder%%~1\PrintHood" call :RM_SUB "%folder%%~1\PrintHood" >nul
@if exist "%folder%%~1\Recent" call :RM_SUB "%folder%%~1\Recent" >nul
@if exist "%folder%%~1\Cookies" call :RM_SUB "%folder%%~1\Cookies" >nul
if "%~1" == "" (
echo Usage: DelFolder.cmd FolderName
for /F %%f in ('dir /A: "%~1"') do (
attrib -R -S -H "%~1\%%f" /D /S
echo "Deleting all files from %~1\"
echo "Deleting all files from %~1\" >> c:\deltemp.log
@del /f /s /q "%~1\*.*" >nul
@for /D %%d in ("%~1\*") do (
rem echo "z1:" %%d
attrib -R -S -H "%%d\*.*" /D /S
echo "Deleting folder %%d"
echo "Deleting folder %%d" >> c:\deltemp.log
rmdir /s /q "%%d" >nul
Tuesday, February 22, 2011
The difficulty is called 'local variables'. As far as you know, to retrieve the value of certain variable, you have to use the following construction: %variable_name%. But if you use your variable inside a loop, and its value is being changed on each iteration, you should not use this way to access the variable. Try to place %variable_name% inside a loop, and you will retrieve the same value every time. Thus you have to use setlocal enabledelayedexpansion and write !variable_name! instead (don't forget to use endlocal after a loop).
It is not very hard to follow this small tip, just don't forget to use it while you write batch files.
Thursday, February 17, 2011
Sunday, February 13, 2011
echo list volume>"%temp%\ds.txt"
for /f "skip=8 tokens=3" %%a in ('diskpart /s "%temp%\ds.txt"') do set "used=!used! %%a"
del /q "%temp%\ds.txt" 2>nul
echo The used letters are - %used:~1%
Hope this batch file will be really useful for you.
Friday, February 11, 2011
for %%i in (*.js) do COPY /B %NewFile%+%%i %NewFile%
move %NewFile% ..\%NewFile%
It is useful to store the current version of the resulting JS in top of the file. Here is code that automatically reads and increments the version of the script before merging all files:
set /p vers=
for /f "tokens=2 delims==" %%i in ("%vers%") do set /a ver=%%i+1
echo var vers=%ver%
more +1 result.js
for %%i in (*.js) do copy /b main.tmp+%%i main.tmp
ren main.tmp result.js
Have any ideas about further enhancements? Don't hesitate to post your comments or send your suggestions to us!
Wednesday, February 9, 2011
Here is the code:
> #.SCR ECHO N _CHO.COM
>>#.SCR ECHO E 0100 BB 80 00 43 80 3F 0D 75 FA C6 07 24 B4 09 BA 82
>>#.SCR ECHO E 0110 00 39 DA 7F 02 CD 21 B4 4C CD 21
>>#.SCR ECHO RCX
>>#.SCR ECHO 001B
>>#.SCR ECHO W
>>#.SCR ECHO Q
_CHO %DATE% >TEST.TXT
_CHO TEST FIRST WORD >>TEST.TXT
_CHO TEST SECOND WORD >>TEST.TXT
As far as you can see, this code produces a small COM file that is able to print text without closing CR\LFs. Of course, you can easily edit the batch script and rename this COM file from _CHO to any name you prefer. Hope you'll find this post useful.
Saturday, February 5, 2011
Thursday, February 3, 2011
for /f "tokens=*" %%a in (items.txt) do set /a "lines+=1"
set /a "skip=%random% %% lines"
if %skip% lss 1 (set "skip=") else (set "skip=skip=%skip%")
for /f "%skip% tokens=*" %%a in (items.txt) do set "item=%%a"&goto display
Hope it'll be useful, or at least just amazing for you.
Tuesday, February 1, 2011
How to Sort Out Files of Differnet Types with Help of Batch Files, Chapter II: Sorting Text Files by Their Contents
So here is the example that can be used in sorting LOGs of different applications or downloaded files, or in other suitable cases. The script searches for the given phrase in all text files placed in the current folder, and if the phrase is found, the file that contains it is replaced to the specified folder.
for %%i in (*.txt) do (
find "first phrase" "%%i" > nul && MOVE "%%i" 1
find "second phrase" "%%i" > nul && MOVE "%%i" 2
rem Add here your phrases.
Hope this script will be useful for you.
Thursday, January 27, 2011
Here is the code of this batch file:
@echo off regedit /ea %Temp%\ChkReg.txt "HKEY_CURRENT_USER\Software\MyPrg-1" if exist %Temp%\ChkReg.txt type %Temp%\ChkReg.txt>reg.reg regedit /ea %Temp%\ChkReg.txt "HKEY_LOCAL_MACHINE\Software\MyPrg-1" if exist %Temp%\ChkReg.txt findstr /v /b /i "REGEDIT4" %Temp%\ChkReg.txt>>reg.reg if exist %Temp%\ChkReg.txt del %Temp%\ChkReg.txt
As far as you can see, first of all we export the necessary keys to ChkReg.txt, than copying data itself to REG file, and then remove the temporary TXT. Hope this script will be useful for you.
Tuesday, January 25, 2011
Here is a useful script that administrators can use to retrieve automatically files from the network drive and pack them immediately after that. All the actions are being logged to the LOG file called by default 1.log. You can easily modify this script with help of Dr.Batcher, a powerful utility designed to create and modify batch files.
@echo Starting>> 1.log
@DATE /t >> 1.log
@TIME /T >> 1.log
@echo Copying and logging results ...
@xcopy v:\post\*.doc /z /c /Q >> 1.log
@echo Packing... >> 1.log
@rar a -ag + YYYY:MM:DD:HH:MM \*.doc >> 1.log
@echo Moving the archive to TEMP folder... >> 1.log
@move *.rar TEMP
@echo Removing DOC... >> 1.log
@del /F d:\*.doc
@echo Done... >> 1.log
Have any suggestions on this batch file? Leave your comments!
Saturday, January 22, 2011
Hope you'll find this code useful.
Wednesday, January 19, 2011
1. Download and install Dr.Batcher, the program designed to create and edit batch files.
2. Start Dr.Batcher and create new empty batch script (File->New->Empty Batch Script).
3. Add command named "Display a message" (Command->Add), click OK in the "Add Command" dialog.
4. Choose "off" as the first parameter and click "OK".
5. Add command named "Set Label".
6. Set loop as a label name, click "OK".
7. Add command named "If (Condition)". Choose "Edit the condition" in the appeared dialog.
8. Choose "File Exists (Condition Only)". 9. Set the letter of the flash drive as the parameter in the following dialog. Note: "\." after the drive letter should not be removed.
9. Add command named "Go to a Label".
10. Set loop as the label name. Click "OK".
11. Following the instructions in paragraphs 5 and 6, add a label with name end.
12. Add command named "Shut Down or Restart Computer".
13. Set the first parameter of this command equal to -r to restart or -s to shut down
14. To make this file start automatically when you log on, place it inside the "Startup" folder in Start menu.
Monday, January 17, 2011
- new options for changing the way of starting Dr.Batcher;
- support for storing spaces between command name and its parameters;
- tabbed "Common Options" dialog;
- improved compatibility with 32-bit Windows 7;
- small bugfixes.