I want to create a rar archive whitch one to have a files from a folder and to check if there is existing archive with the same name, if so to make the name of the archive increasing with 1 (if have file archive.rar to create archive1.rar, archive2.rar …). Almost everything is used of the internet, because i am learning it from a few days, but it didnt work as i want it to.
This work by adding the date and the time in the name, but I want to be able to set the name as I want.
@echo off
set d=%DATE:~6,4%.%DATE:~3,2%.%DATE:~0,2%
set t=%TIME:~0,2%.%TIME:~3,2%.%TIME:~6,2%
echo %d%-%a%
echo The archive is creating
"C:Program FilesWinRARRar.exe" a -ep1 -r0 "C:DesktoptesttopDate%d%Time%t%.rar" "C:...Desktoptesta*.*"
echo The archive is created with the name Date%d%Time%t%.rar
pause
This one create a folder and add the archive into the folder, if I try to remove md “%baseName%%n%” and remove it from the path “C:…Desktoptesttop –> %baseName%%n% <– %baseName%%n%.rar” to create only the rar file, it create 1 archive with the name New_Folder1.rar and next time i run it, it create the same one New_Folder1.rar. It didn’t check if there is an existing one and to increase the number in the name.
@echo off
setlocal enableDelayedExpansion
set "baseName=New_Folder"
set "n=0"
for /f "delims=" %%F in (
'2^>nul dir /b /ad "%baseName%*."^|findstr /xri "%baseName%[0-9]*"'
) do (
set "name=%%F"
set "name=!name:*%baseName%=!"
if !name! gtr !n! set "n=!name!"
)
set /a n+=1
md "%baseName%%n%"
echo the new name is %baseName%
"C:Program FilesWinRARRar.exe" a -ep1 -r0 "C:...Desktoptesttop%baseName%%n%%baseName%%n%.rar" "C:...Desktoptesta*.*"
pause
1V1S1BL3 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.