increment archive name

Microsoft Windows xp professional w/serv...
May 23, 2010 at 01:55:14
Specs: Windows XP, 1700/2g
hi
i have a batch file to make an archive.
the archive name is arh001.zip
i want batch file to increment that 001 each time i do an new archive.
10x

See More: increment archive name

Report •


#1
May 23, 2010 at 02:42:22
Does it need to discover the las used number?


=====================================
Helping others achieve escape felicity

M2


Report •

#2
May 23, 2010 at 08:10:22
the last number should be saved into another file i think, and before i do archive, to read the number in that file and increment, then use in the name of archive ...

u see another solution ?


Report •

#3
May 23, 2010 at 11:40:20
@echo off & setlocal
for /f "tokens=*" %%a in ('dir /b /o-n /a-d arh*.zip') do set test=%%~na
set test=%test:arh=%
:10
if %test:~0,1 equ 0 set test=%test:1% & goto 10
:11
set /a test+=1
set test=000%test%
set newarc=arh%test::~-3%.zip
echo %newarc%
::----- end
another way would be to simply count all the arh*.zips:
for /f %%a in ('dir /b /a-d arh*.zip ^|find /v /c ""')

then resume from label :11 down.
I tend to think these kinds of methods are better than storing
value in a file since the file could become corrupted.


Report •

Related Solutions

#4
May 24, 2010 at 09:10:25
thank you, but i cant use that becouse i dnt keep the archives on pc, ... because of this i want to use another file to store and increment that number...

Report •

#5
May 24, 2010 at 15:46:16
@echo off & setLocal EnableDELAYedeXpansion

if exist %TEMP%\ZIPnum (
set /p N=<%TEMP%\ZIPnum
if !N! lss 100 set Z=0!N!
if !N! lss 10 set Z=00!N!
set /a N+=1
> %TEMP%\ZIPnum echo !N!
) else (
set Z=000
> %TEMP%\ZIPnum echo 0
)
echo next zip is arh!Z!.zip


=====================================
Helping others achieve escape felicity

M2


Report •

#6
May 29, 2010 at 02:46:39
thank you, it's ok.

Report •

#7
May 29, 2010 at 08:58:24
Good solution from M2 but I wouldn't use %TEMP% because it's not actually temporary. Anything in %TEMP% can be deleted at any time (or at least that is the idea of temp). You don't want to lose the ZIPnum file. You could instead put it in %APPDATA%\yourname\ZIPnum.

Report •

Ask Question