Page 1 of 1

Compare two directory

Posted: 25 Oct 2022 11:16
by darioit
Hello,
could you help me to batch compare a directory to find missing couple of file?

Example existing couple, same name "AB12345_DEF1234_20220105" and 2nd file has another qualifier "_XYZ1234567"
C:\Data\AB12345_DEF1234_20220105.pdf
C:\Data\AB12345_DEF1234_20220105_XYZ1234567.pdf

example missing both type
C:\Data\AB56789_DEF9876_20220125.pdf Missing AB56789_DEF9876_20220125_ABC1234567.pdf
C:\Data\GH54321_LMN9876_20220115_XYZ7654321.pdf Missing GH54321_LMN9876_20220115.pdf

Sometimes is missing 1st row, sometimes 2nd and

Thank you in advance
Dario

Re: Compare two directory

Posted: 25 Oct 2022 15:37
by aGerman
Provided the number of tokens separated by an underscore is always 3, and 4 for the sibling:

Code: Select all

@echo off &setlocal
pushd "C:\Data"
for /f "delims=" %%i in ('dir /a-d /b "*.pdf"^|findstr /rix "[^_]*_[^_]*_[^_]*\.pdf"') do (
  if not exist "%%~ni_*.pdf" echo lone: "%%~i"
)

for /f "delims=" %%i in ('dir /a-d /b "*.pdf"^|findstr /rix "[^_]*_[^_]*_[^_]*_[^_]*\.pdf"') do (
  for /f "tokens=1-3 delims=_" %%j in ("%%~i") do if not exist "%%j_%%k_%%l.pdf" echo lone: "%%~i"
)
popd
pause
Steffen

Re: Compare two directory

Posted: 25 Oct 2022 23:33
by darioit
Perfect, works fine and very fast, I don't considered using token with delims _ in my script!

Many thanks
Dario