In my current folder, I have a file named backup(yyyy-mm-dd).7z
I need to keep that length
variable even though here it is a constant.
@echo off
setlocal EnableDelayedExpansion
set "a=.\backup"
set "b=yyyy-mm-dd"
set "length=19"
for %%f in (.\*) do (
set "fullpath=%%f"
set "trimpath=!fullpath:~0,%length%!"
set trimpath
echo trimpath=%trimpath%
if %trimpath% == %a%(%b% echo this is equal
)
I have 2 questions regarding that code:
set trimpath
but not directly with %trimpath%
?Here is the solution after following @foxidrive and @JosefZ advices!
@echo off
setlocal EnableDelayedExpansion
set "a=.\backup"
set "b=yyyy-mm-dd"
set "length=19"
for %%f in (.\*) do (
set "fullpath=%%f"
set "trimpath=!fullpath:~0,%length%!"
echo trimpath=!trimpath!
if "!trimpath!" == "%a%(%b%" echo this is equal
)
If you need to test the solution, just create a file named backup(yyyy-mm-dd)
in your current folder.