Вопрос

The following script search thru a folder and its sub-folders and then compares each file it gets to files in the 2nd folder. If found it echo's a message to say that the file was found.

My question is how do I enhance this script to search the 2nd folder and its sub-folders for the file found in 1st dir? I only care about the file-name with extension (I do not care in which folder/sub-folder it was found, just that a duplicate file is present and causing compiler errors)

I thought one of the ways would be to output all file names to a file and then take the file as input in 2nd part and loop thru the 2nd folder, but I am sure there must be a cleaner way.

O/S: Windows 2003

:bof
    rem @echo off
    cls
    setlocal
:init
    set dirA=X:\tst\pfsrc\
    set dirB=X:\tst\cbsrc\
    if not exist "%dirA%" echo dirA not found & goto :EOF
    if not exist "%dirB%" echo dirB not found & goto :EOF
    for /f "delims=" %%I in ('dir /b /a:-d /s "%dirA%" 2^>NUL') do if exist "%dirB%%%~nxI" echo %%~nxI does exist in "%dirB%" 
:eof
Это было полезно?

Решение 2

Thank you for putting me on the correct track :-) Code now works

:bof
    @echo off
    cls
    setlocal
:init
    set dirA=X:\tst\pfsrc\
    set dirB=X:\tst\cbsrc\
    if not exist "%dirA%" echo dirA not found & goto :EOF
    if not exist "%dirB%" echo dirB not found & goto :EOF
    for /f "delims=" %%I in ('dir /b /a:-d /s "%dirA%" 2^>NUL') do for /r "%dirB%" %%d in (%%~nxI) do if exist "%%d" echo %%d
:eof

Другие советы

this excerpt will try to find %%a in all dirs of %dirB% recursively

for /d /r %%d in (%dirB%\*) do (
  if exist "%%d\%%~nxa" echo %%d\%%~nxa
)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top