I cleaned up the code that should delete files that have no names starting with keep . I achieve this by putting the file name in tmpL1 and tmpL2 when replacing the keep value with nothing. If tmpL1 and tmpL2 different, I save the file, otherwise it is deleted.
setlocal enabledelayedexpansion set keep=[File I want to keep] for /F %%L IN ('dir /b *') do ( set tmpL1=%%L set tmpL2=!tmpL1:%keep%=! if !tmpL1!==!tmpL2! ( echo.[REMOVE] ) else ( echo.[KEEP] ) )
It works great. However, when I put this code in a larger script, installing tmpL2 suddenly stops working. Instead (part), the tmpL2 file tmpL2 now literally contains tmpL1:= .
Here is the script I want to use it. Additional for -loops are intended only for viewing the directory tree. The main script function remains the same.
setlocal enabledelayedexpansion for /F %%G in ('dir /b *-snapshots') do ( set tmpG1=%%G for /F %%H in ('dir /b !tmpG1!\*') do ( set tmpH1=%%H for /F %%I in ('dir /b !tmpG1!\!tmpH1!\*') do ( set tmpI1=%%I for /F %%J in ('dir /b !tmpG1!\!tmpH1!\!tmpI1!\*-SNAPSHOT') do ( set tmpJ1=%%J set tmpJ2=!tmpJ1:~0,8! for /F %%K in ('dir /b !tmpG1!\!tmpH1!\!tmpI1!\!tmpJ1!\*!tmpJ2!*.pom /O:N') do ( set tmp1=%%K ) set keep=!tmp1:.pom=! for /F %%L in ('dir /b !tmpG1!\!tmpH1!\!tmpI1!\!tmpJ1!\*!tmpJ2!*') do ( set tmpL1=%%L set tmpL2=!tmpL1:%keep%=! pause if !tmpL1!==!tmpL2! ( echo.[REMOVE] ) else ( echo.[KEEP] ) ) ) ) ) )
I also tried the "lazy" slow extension, replacing set tmpL2=!tmpL1:%keep%=! on call set tmpL2=%%tmpL1:%keep%=%% . This also works in a small script, but when I apply it to a large one, I get an error, for example, "=%" can't be syntactically processed in this location (which is a free translation, since my console is in German).
Does anyone have an idea what causes this?
source share