Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Actually, i have to compare two excel file that are in placed in Two different folders.
Eg. Folder1. Abc_rpt1 and Folder2. Xyz_rpt1.
Note, in both the folders report template is same but report name and the values are different. In both the folders the reports are in the same sequence like in first place we have abc_rpt1 in second place abc_rpt2 same as i. Folder2 Xyz-rpt1 and Xyz_rpt2. Now, in my code it is comparing the report when the report name in both the folders will same.

What I have tried:

@echo off
set /p "MasterFolder1=MasterFolder1:"
set /p "MasterFolder2=MasterFolder2:"
Set "LogFile=%~dpn0.txt"
If exist "%LogFile%" Del "%LogFile%"

Set "PECfolder=C:\SunilKK-Latitude-E6430s\SunilKK\Software\PreciseExcelComparator\v1.1\PreciseExcelComparator_PEC"
::echo %PECfolder%
PushD "%PECfolder%" || ( Echo can't locate %PECfolder% &Pause&Exit /B 0)

FOR /f "delims=" %%f IN ('dir /b /s "%MasterFolder1%\*.xls"') do (
::echo %MasterFolder1%
    If exist "%Masterfolder2%\%%~nxf" (
        call java -jar "C:\SunilKK-Latitude-E6430s\SunilKK\Software\PreciseExcelComparator\v1.1\PreciseExcelComparator_PEC\PEC.jar" "%%~ff" "%Masterfolder2%\%%~nxf" 0 0
    ) else (
        echo No pendant to "%%f" found in "%MasterFolder2%" >> %"LogFile%"
    )
)
pause
Posted
Updated 10-Sep-19 22:47pm
v2
Comments
Maciej Los 11-Sep-19 2:34am    
And your question is...
Sunil KK 11-Sep-19 2:52am    
Hello Maciej Los, i didn't find your answer?
Maciej Los 11-Sep-19 2:53am    
Because i haven't posted it.
Sunil KK 11-Sep-19 3:00am    
Ok, first of all thanks for showing interest on my query. Well, can you please confirm what is wrong i am doing in my code.
Maciej Los 11-Sep-19 3:11am    
I have no idea what is wrong... You told us what your code is doing right now and you didn't tell what you are trying to achieve. Can you provide more details about your issue?

1 solution

Seems, your code is incomplete, because you have to compare each file in folder1 with all files in folder2. See: Cartesian product[^].
In pseudo-code:
Set "PECfolder=C:\SunilKK-Latitude-E6430s\SunilKK\Software\PreciseExcelComparator\v1.1\PreciseExcelComparator_PEC"
Set "PECfile=pec.jar"

REM ... some lines were skipped

FOR /f "delims=" %%f1 IN ("%Masterfolder1%\*.xls") DO (
    FOR /f "delims=" %%f2 IN ("%Masterfolder2%\*.xls") DO (
        REM compare last 5 characters + ".xls" of file
        IF %f1:~-9% == %f2:~-9%
                call java -jar %PECfolder%\%PECFile% %f1% %f2% 0 0
    )
)
 
Share this answer
 
v3
Comments
Sunil KK 11-Sep-19 4:55am    
Hello Maciej,

I don't have to compare each file in folder1 with all files in folder2

I have to compare file like report1 to report1 and report2=report2, report3=report3. As report name is not same in both the folder. So, i am assuming that in both the folders the sequence of file is same.
Maciej Los 11-Sep-19 5:00am    
But you mentioned that the name of files can differ each other. The common part of files is a template. So, i guess that you have to compare each file in one folder to all files in second folder. If the part of file name is the same in both folders, you have to add another condition, but logic is still the same.
Sunil KK 11-Sep-19 5:07am    
Yes, as i mentioned in comments i have file name in this manner :

Folder1
C:\Users\kaushasu\Desktop\Test1\F12162-AE EBA2.9-XLS-QA-BF - AE CRD F32.01

Folder2
C:\Users\kaushasu\Desktop\Test2\F12162-AE EBA2.9-XLS-QA - AE CRD F32.01

that's why i am seeking for a help to get the file name for PEC.jar as a parameters
Sunil KK 11-Sep-19 5:11am    
can you just help me to get the filenames in both the folders one by one and executed with pec.jar, it would be like :

call java -jar C:\PreciseExcelComparator\PEC.jar "C:\Users\kaushasu\Desktop\Test1\F12162-AE EBA2.9-XLS-QA-BF - AE CRD F32.01.xls" "C:\Users\kaushasu\Desktop\Test2\F12162-AE EBA2.9-XLS-QA - AE CRD F32.01" 0 0

call java -jar C:\PreciseExcelComparator\PEC.jar "C:\Users\kaushasu\Desktop\Test1\F12162-AE EBA2.9-XLS-QA-BF - AE CRD F32.02.xls" "C:\Users\kaushasu\Desktop\Test2\F12162-AE EBA2.9-XLS-QA - AE CRD F32.02" 0 0

call java -jar C:\PreciseExcelComparator\PEC.jar "C:\Users\kaushasu\Desktop\Test1\F12162-AE EBA2.9-XLS-QA-BF - AE CRD F32.03.xls" "C:\Users\kaushasu\Desktop\Test2\F12162-AE EBA2.9-XLS-QA - AE CRD F32.03" 0 0

this should be run in the loop.
Sunil KK 11-Sep-19 7:17am    
Hello Maciej Los, am i able to explain ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900