0

I am working on a batch file where I need to compare each line of for loop A and for loop B in order to execute another command, but I can't seem to figure this one out. Any help would be greatly appreciated. The code I have so far is listed below.

@echo OFF
SetLocal EnableDelayedExpansion
for /f "delims=" %%A in ('Type "%Paths%"') do (echo %%~nxA)
pause
for /f "delims=" %%B in ('Type "%Names%"') do (echo %%B)
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Please let us know if the duplicate doesn't answer your question or when you have problems adapting it to your needs. – Stephan Jul 22 '22 at 16:56
  • Stephan. The duplicate doesn't answer my question. From the code above, I am reading one text file and getting just the file name from the full file paths and reading a second text file listing the files names themselves. I then need to compare those results and if they are equal, then I need to zip up the file listed in the full file path. – Roger Martin Jul 22 '22 at 17:26
  • 1
    why not just use findstr: `For /f Delims^= %%G in ('%SystemRoot%\System32\findstr.exe /G:"names.txt" "paths.txt"')Do Echo(%%~nG found in %%G` – T3RR0R Jul 22 '22 at 17:46
  • [Comparison of the lines with batch](https://stackoverflow.com/a/50068272/778560) – Aacini Jul 23 '22 at 00:09

2 Answers2

1

I adapted the linked duplicate to your requirements (untested, because I have no exact information about your source files)

@echo off
setlocal enabledelayedexpansion

<"%NAMES%" (
  for /f "delims=" %%A in ("%PATHS%") do (
    set /p b=
    if "%%~nxA" == "!b!" (
      echo here zip "%%A" 
    )
  )
)
Stephan
  • 53,940
  • 10
  • 58
  • 91
0

setlocal enabledelayedexpansion

for /f "delims=" %%B in ('Type "%Names%"') do (
for /f "delims=" %%A in ('Type "%Paths%"') do (
  if "%%~nxA" == "%%B" (echo "We have a match.")
  )
)

Thank you for everyone's assistance.