0

First of, I read some /help and thread like this one : Comparing two files in batch script

but this is chinese to me.

I'm experienced in C/C++ programming only (Linux/UNIX) and I'm getting stuck for a batch script on ma dear windows.

Here the problem : I have two files (file1.txt (or logOK.txt in the below source code) and file2.txt) which looks like

file1.txt : dir1;dir2;dir3;dir4;...

file2.txt : dir7;dir3;dir4;dir1;...

(files aren't ordered by name ASC or whatever but they all have a ';' as separator)

What I want my .bat to do is to compare file1.txt to file2.txt and when something match (here dir 1, 3 and 4) it will echo [folderX] >> file3.txt

so I'll get a file3.txt : dir1;dir2;dir3

Here is the first part (wich works well, actually) of the script which check if the directories are empty or not, if it can help : (there is some debugs lines too)

@echo off
setlocal disabledelayedexpansion

if exist logKO.txt del /s logKO.txt
if exist logOK.txt del /s logOK.txt

set "folder=."
if not defined folder set "folder=%cd%"

for /d %%a in ("%folder%\*") do (
    set "size=0"
    for /f "tokens=3,5" %%b in ('dir /-c /a /w /s "%%~fa\*" 2^>nul ^| findstr /b /c:"  "') do if "%%~c"=="" set "size=%%~b"
    setlocal enabledelayedexpansion
    if !size! EQU 0 echo %%~nxa; >> logKO.txt
    if !size! NEQ 0 echo(%%~nxa # !size!
    if !size! NEQ 0 echo/| set /p = "%%~nxa;" >> logOK.txt
    endlocal
)
endlocal

Thanks for help

Community
  • 1
  • 1

1 Answers1

1
@ECHO OFF
SETLOCAL enabledelayedexpansion

:: read in the two lists

FOR /f "delims=" %%a IN (q26907961a.txt) DO SET "list1=%%a"
FOR /f "delims=" %%a IN (q26907961b.txt) DO SET "list2=%%a"

:: Bippity Boppity Boo

SET "list1="%list1:;=";"%""
SET "list2="%list2:;=";"%""
SET "list3="

FOR %%a in (%list1%) DO FOR %%b IN (%list2%) DO IF %%a==%%b SET "list3=!list3!;%%~a"
SET list3=%list3:~1%

SET list

GOTO :EOF

I used files named q26907961a.txt and q26907961b.txt containing your data for my testing.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • OH man thanks a lot, this is perfect ! And very, very easier to understand ! Bippity Boppity Boo to you too ! ;p – user3210859 Nov 13 '14 at 13:22