ContactEZ.net D. G. Schneider International Lions Club Volunteer Project

ContactEZ.net

Batch Process - Bulk Process

Small enterprises more than any other enterprises need to increase their efficiency. You have powerful computers, modern operating systems, and great employees. That's not all. You can get the best of your investment by creating automation scripts, batch files, and utilities. Humans created machine to have them do the repetitive tasks. Your computer is made to do repetitive tasks as any other machine. You can use automation utilities to schedule jobs and tasks to occur during off-hours and weekends for example. You do not need to buy software for every repetitive routine. The Operating System offers most of what you need to to increase user's productivity. Automation should become a reflex.

DOS batch commands need sometime to be modified to include a provision to close a Dos window after executing a routine.

On Windows 98 and Windows Me, you may need to add:

@echo off
@cls

This will close the DOS window and allow the next statement to be executed in your automated process.
On Windows NT and 2000 these two lines are not necessary even though I would advice to place them anyway.

Some Syntax Examples:

To change to the drive D on a PC type in the Batch file:
D:
Assign a path:
set DIRTOUSE=%1
or to assign this path
set DIRTOUSE=D:

To check if the drive exists on the PC type in the Batch file:
if not exist %DIRTOUSE%\NUL goto DIR_ERR

To change to the active directory:
cd /d %DIRTOUSE%\

To create sub-folders named Folder1, Folder2, Folder3 type in the Batch file:
mkdir Folder1 Folder2 Folder3

To delete sub-folders (directories) and there contents:
cd /d %DIRTOUSE%\
rmdir /s /q

To check if a variable is missing type in the Batch file:
if "%MY_DRIVE%"=="" goto TellUser

To inform the user type in the Batch file:
:TellUser echo ******* MY_DRIVE is not defined ******* >c:\Mytemp\BatchErr.txt Pause goto END

To assign preferences type in the Batch file:
if "%MyCOMPUTERNAME%" == "DOMINIQUE" set PreferedEditor=C:\Pfe\Pfe.exe

To specifiy a path:
set MyTOOLS="C:\Program Files\Tradiciel\Tradiciel.exe"

To check if user entered a parameter type in the Batch file:
if "%1"=="" goto ERR
To assign the path type in the Batch file:
set MyWorkingDir=%1

To inform the user type in the Batch file:
:ERR echo USAGE: %0 Missing Directory To Work With!
goto STOP

To run a command against files located on another machine:
set The_COMMAND=My_Program.exe
%The_COMMAND% -myflag \\My_Server\My_Projects\%DIRTOUSE%\My_Sub_Folder\My_ZIP_File.zip

To substitute a drive with the letter O:
subst /d O:
subst O: D:\My_Working_Folder\My_Working_SubFolder

To connect to a drive with the letter P:
subst /d P:
net use P: /delete
net use P: \\My_Server\My_Projects

To launch an executable:
call C:\Program Files\Tradiciel\Tradiciel.exe
(or call C:\Program Files\Tradiciel\My_Program.exe %1 %2)

To write a log file named My_Job.log and located on the O drive:
echo Finished to replace strings... >O:\logs\My_Job.log
echo Copying all TXT files to O:\Domi... >>O:\logs\My_Job.log

To launch a BAT file from a BAT file and keep a log of the process:
call MyBatchFile.bat > O:\logs\My_Job.log 2>&1

To copy the content of a folder (directory):
XCopy C:\Program Files\Tradiciel\Databases\*.* D:\My_Project\Bkp\CD\Databases\ /s /e

To delete all the files with the .OLD extension from a directory structure:
Del /S D:\My_Project\*.old

To clean a directory structure, recreate it, and make it the active directory:
rmdir /s/q D:\My_Project
Mkdir D:\My_Project
CD /d D:\My_Project

Example of MyBatchFile.bat :
=============================

@echo off

D:
cd D:\
set DIRTOUSE=D:\Folder1

if not exist %DIRTOUSE%\NUL goto Mk_DIR

:KeepWorking
subst /d O:
subst O: %DIRTOUSE%

O:
cd /d O:\Domi
Copy C:\Temp\MyExample.txt "O:\Domi"
Dir
pause
goto End

:Mk_DIR
mkdir Folder1 Folder1\Domi Folder2 Folder3
goto KeepWorking

:End

=============================

Launching an application:

PATH = "C:\Program Files\Microsoft Office\Office\;C:\Windows\Command"
CD C:\your working folder
START /WAIT Msaccess.exe "C:\Program Files\Microsoft Office\Office\Samples\YourData.mdb" /x "Name Header DataWarehouse"
COPY * C:\Data_Folder\DataWarehouse
EXIT

Search the Microsoft web site with key words as CmdHere, (Open Command Window Here adds context menu option on file system folders, giving you a quick way to open a command window (cmd.exe) pointing at the selected folder), "Tweak UI", "Image Resizer", "CD Slide Show Generator", "Webcam Timershot", ... they offer a lot of free tools.

About Dominique Gérard Schneider since 1995
Participation on Google
ContactEZ.net on YouTube

Tek-Tips Forums dgschnei
Listed since 1996 ixquick
Community Services

platform sdk dgschnei
Cooperation
About Me
Gifts Home Decoration

Return Home - Index