Thursday, July 14, 2011

Copy Files and Automatically Rename Existing Ones

Usually while copying large amount of files it is necessary to rename the existing files to avoid overwriting them with the copied ones. Usual commands like copy or xcopy don't let you perform renaming in automatic mode. Still you are able to create a batch script that will help you to solve this problem:
@echo off
for %%i in (SourceDir\*) do (
if exist "DestDir\%%~nxi" (
mv "%%i" "DestDir\~%%~nxi"
) else (
mv "%%i" "DestDir"
)
)

You can change this example script according to your needs with the help of our batch files editor. Hope you'll find this small example useful.

Saturday, July 9, 2011

Script for 'Remote Execution' of Programs

It is useful sometimes to download a program from a remote server and run on the computer where the batch script is running. It is not so hard to implement it:
title Loading program... Please wait...
@echo off
net use w: \\192.168.x.x\a1 > nul
echo "1. Disk connected"
cd d:\
d:
md 123
cd d:\123
md Program
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"
exit

You can change this batch file with help of our award-winning batch files editor. Hope you'll find this example useful.

Translate