-----Original Message-----
Frank said:
I am trying to find a way to copy a file to a specific
folder and not overwrite the existing file using either
batch file or scripting.
For ex.
copy test.txt c:\backup\test(variable).txt
any suggestions?
Should (variable) be a counter to increase in case the file exists?
::CopyCount.cmd::::::::::::::::::::::::::::::::::::::::::: ::::::::::::
@echo off & setlocal enableextensions
if [%1]==[] goto :Usage
if [%2]==[] goto :Usage
set Cnt=1
set DestAttr=%~a2
if [%DestAttr:~0,1%]==[d] (
set Dest=%~f2\%~n1
set ext=%~x1
) else (
set Dest=%~dp2%~n2
set ext=%~x2
)
if NOT exist "%dest%%ext%" (
copy %1 %Dest%%ext%
) else (
:loop
if exist "%Dest%(%Cnt%)%ext%" set /A Cnt+=1&goto :loop
copy %1 "%Dest%(%Cnt%)%ext%"
)
goto :EOF
:Usage
echo/Usage: %~n0 Source Dest (Dest may be file or folder)
echo/
echo/if Dest exists a number in parenthes is appended.
echo/if Dest with number exists the number is increased.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::
HTH
--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm
.