folder B contains: abc_file1.xml, ddd_file2.xml, ccc_file4.xml
objective:
I'm trying to go through folder A and take just the file name and see if that filename exists in the files listed in folder B.
so file1 would compare abc_file1, ddd_file2, ccc_file4 and it would return file exists only for abc_file1.xml. Then it would go through file2 and looks through folder B. etc.
I'm always returning errorlevel 0. I know it's the findstr but I'm not sure why?
any help would be appreciated.
thanks
Code: Select all
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
:: folder A
FOR /f "tokens=*" %%a IN ('dir /b *.xml') DO (
:: folder B
FOR /f "tokens=*" %%b IN ('dir /b H:\*.xml') DO (
SET "oldName=%%~na"
SET "newName=%%~nb"
ECHO OLD: !oldName!
ECHO NEW: !newName!
echo !oldName! |findstr /i "!newName!" > nul
IF !ERRORLEVEL! == "1" (
echo matched
) ELSE (
echo no match
)
)
)