Sunday, August 28, 2011

Sorting Web Pages Archive

The task is to sort the archive of different Web documents.

There is a plenty (about 5 thousands) of files named the following way:
number(3-6 digits),sis)
And the same amount of images in 'Screens' folder:
number(3-6 digits).jpg(gif,png)
Alse there are Web pages in 'Html' folder:
number(3-6 digits).htm(html)
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:

@Echo Off
Set ArcDir=c:\archives
Set ScreenDir=c:\screens
Set HTMLDir=c:\html
Set OutDir=C:\
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

Installing Many Programs at Once

It takes a lot of time to install different software on the users' workstations. It is much easier to run a single batch script created with the award-winning batch files editor and install all these programs immediately. The script will look like this one:
@echo off
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

Retrieving the List of Files Modified Lately

It's quite a common task to retrieve the list of files modified during the latest few days. It is easy to solve this task with the help of batch files:
@echo off
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

Clearing Sub-Folders in the Given Folder

Imagine: you have a shared folder where users can create there own sub-folders. Sometimes it is necessary to clean the whole shared folder, but the cleaning batch script has to leave all the sub-folders and just delete everything inside them. How to perform it? The small script below shows you quite an easy way to solve this problem. Hope you'll find it useful.
@echo off
pushd "U:\Share Folder"
for /d %%i in (*) do (
pushd "%%i"
rd /s /q "." 2>nul

Wednesday, August 10, 2011

Removing Unnecessary Dots and Slashes from Date

When you want to use the current date as a part of a file's name, you want to see something like '01012011'. Usual 'date' variable gives you human-readable date with additional dots looking like this: '01.01.2011'. Or something like this: '01/01/2011'. It depends on the settings of your copy of Windows. Fortunately, it is not hard to remove unnecessary characters from the string with the date. All you need to do is to use the following construction:
echo %date:.=%
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

Search for a File on Local Drives

We all need sometimes to find a certain file on a local disk drive. It is not hard to implement search by name with the help of batch files. But what to do if you need to search for a file on all the drives available on a computer? The example script below shows how to perform it.
@echo off
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
goto :EOF
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.