Saved Bookmarks
| 1. |
Solve : Compare xml files with same name in 2 differnt folders? |
|
Answer» HI every1 , Can some1 help me with a batch code for the description below: Quote ==>I have many xml files in two different folders.ANY SUGGESTIONS? THANKS IN ADVANCE Replace the variable values with the names of the folders you wish to compare and the destination. IT WILL NOT PROMPT WHEN OVERRIDING FILES, so be careful. Code: [Select]echo off setlocal EnableDelayedExpansion set folder1=Folder1 set folder2=Folder2 set folder3=Diff if not exist %folder3% md %folder3% cd %folder1% for /f "delims=" %%A in ('dir /b') do ( cd ..\%folder2% cls echo Processing File "%%A", Please Wait . . . if not exist %%A ( cd ..\%folder1% move %%A "..\%folder3%\%%A" >nul 2>&1 ) else ( fc %%A "..\%folder1%\%%A" >nul 2>&1 if "!errorlevel!"=="1" ( move %%A "..\%folder3%\%folder2% - %%A" >nul 2>&1 move "..\%folder1%\%%A" "..\%folder3%\%folder1% - %%A" >nul 2>&1 ) ) cd ..\%folder1% ) pause Lemonilla Thanks a lot This code works perfectly fine for me Quote But this code moves only files from folder1 which are not in folder2 after comparison to folder3 ,Can u SUGGEST a code which will move the files in folder2 to folder3 at the same time which are not in folder1,I mean to ask u to perform the move operation in both the folders at the same time which are not same..Not sure where to quote is from, but this should work as well. I have not tested this. Code: [Select]echo off setlocal EnableDelayedExpansion set folder1=Folder1 set folder2=Folder2 set folder3=Diff if not exist %folder3% md %folder3% cd %folder1% for /f "delims=" %%A in ('dir /b') do ( cd ..\%folder2% cls echo Processing File "%%A", Please Wait . . . if not exist %%A ( cd ..\%folder1% move %%A "..\%folder3%\%%A" >nul 2>&1 ) else ( fc %%A "..\%folder1%\%%A" >nul 2>&1 if "!errorlevel!"=="1" ( move %%A "..\%folder3%\%folder2% - %%A" >nul 2>&1 move "..\%folder1%\%%A" "..\%folder3%\%folder1% - %%A" >nul 2>&1 ) ) cd ..\%folder1% ) cd ..\%foldere% for /f "delims=" %%A in ('dir /b') do ( cd ..\%folder1% cls echo Processing File "%%A", Please Wait . . . if not exist %%A ( cd ..\%folder2% move %%A "..\%folder3%\%%A" >nul 2>&1 ) else ( fc %%A "..\%folder2%\%%A" >nul 2>&1 if "!errorlevel!"=="1" ( move %%A "..\%folder3%\%folder1% - %%A" >nul 2>&1 move "..\%folder2%\%%A" "..\%folder3%\%folder2% - %%A" >nul 2>&1 ) ) cd ..\%folder2% ) pause It does a second pass though the files to make sure that all the files in the other folder exist in the first. As I said, I have not tested it as I am not at home. Hopefully it's what he wanted.hi thanks lemonilla:-) i had already tried the same way as yo MENTIONED , but it dint work properly i guess , i ll TRY tomorrow in office and let yo no,. . . . thanks again . . . There was a spelling mistake, fixed it: Code: [Select]echo off setlocal EnableDelayedExpansion set folder1=Folder1 set folder2=Folder2 set folder3=Diff if not exist %folder3% md %folder3% cd %folder1% for /f "delims=" %%A in ('dir /b') do ( cd ..\%folder2% cls echo Processing File "%%A", Please Wait . . . if not exist %%A ( cd ..\%folder1% move %%A "..\%folder3%\%folder1% - %%A" >nul 2>&1 ) else ( fc %%A "..\%folder1%\%%A" >nul 2>&1 if "!errorlevel!"=="1" ( move %%A "..\%folder3%\%folder2% - %%A" >nul 2>&1 move "..\%folder1%\%%A" "..\%folder3%\%folder1% - %%A" >nul 2>&1 ) ) cd ..\%folder1% ) cd ..\%foldere% for /f "delims=" %%A in ('dir /b') do ( cd ..\%folder1% cls echo Processing File "%%A", Please Wait . . . if not exist %%A ( cd ..\%folder2% move %%A "..\%folder3%\%folder2% - %%A" >nul 2>&1 ) else ( fc %%A "..\%folder2%\%%A" >nul 2>&1 if "!errorlevel!"=="1" ( move %%A "..\%folder3%\%folder1% - %%A" >nul 2>&1 move "..\%folder2%\%%A" "..\%folder3%\%folder2% - %%A" >nul 2>&1 ) ) cd ..\%folder2% ) pause ) cd ..\%folder1% ) Quote cd ..\%foldere%for /f "delims=" %%A in ('dir /b') do ( cd ..\%folder1% In the above quoted code u have written it as "foldere" ?? "folder2" to be specified there This code also wont move file names with spaces in their names i believe? Pls correct me if i am wrong..Fixed, and Fixed. Code: [Select]echo off setlocal EnableDelayedExpansion set folder1=Folder1 set folder2=Folder2 set folder3=Diff if not exist %folder3% md %folder3% cd %folder1% for /f "delims=" %%A in ('dir /b') do ( cd ..\%folder2% cls echo Processing File "%%A", Please Wait . . . if not exist "%%A" ( cd ..\%folder1% move "%%A" "..\%folder3%\%folder1% - %%A" >nul 2>&1 ) else ( fc "%%A" "..\%folder1%\%%A" >nul 2>&1 if "!errorlevel!"=="1" ( move "%%A" "..\%folder3%\%folder2% - %%A" >nul 2>&1 move "..\%folder1%\%%A" "..\%folder3%\%folder1% - %%A" >nul 2>&1 ) ) cd ..\%folder1% ) cd ..\%folder2% for /f "delims=" %%A in ('dir /b') do ( cd ..\%folder1% cls echo Processing File "%%A", Please Wait . . . if not exist "%%A" ( cd ..\%folder2% move "%%A" "..\%folder3%\%folder2% - %%A" >nul 2>&1 ) else ( fc "%%A" "..\%folder2%\%%A" >nul 2>&1 if "!errorlevel!"=="1" ( move "%%A" "..\%folder3%\%folder1% - %%A" >nul 2>&1 move "..\%folder2%\%%A" "..\%folder3%\%folder2% - %%A" >nul 2>&1 ) ) cd ..\%folder2% ) pause I think this should solve the task in the first post: Code: [Select]echo off set "a=c:\folder1" set "b=c:\folder2" set "c=c:\folder3" md "%c%" 2>nul cd /d "%a%" & for %%z in (*.xml) do if not exist "%b%\%%z" move "%%z" "%c%" cd /d "%b%" & for %%z in (*.xml) do if not exist "%a%\%%z" move "%%z" "%c%" pause Quote from: foxidrive on June 09, 2014, 08:54:24 AM I think this should solve the task in the first post: Not quite though, It should also compare the two if they do exist, so you'd need something like else fc "%%Z" "%a%\%%Z" || move "%%z" "%c%\%%z" at the end of your cd lines Quote from: Lemonilla on June 09, 2014, 01:15:12 PM Not quite though, It should also compare the two if they do exist The task is to move files if they don't exist in both folders, right? Quote from: foxidrive on June 09, 2014, 07:56:23 PM The task is to move files if they don't exist in both folders, right?Quote ==>Some xml files are present in both the folders which are the same with same file name.So if they exist in both, compare the two and move them if they are different. Thus you need to use 'fc'.Thanks Lemonilla and foxi :)U both have done the right way as u have quoted .... and have done it at right time... all the codes wud b useful... Quote from: Lemonilla on June 09, 2014, 09:12:34 PM So if they exist in both, compare the two and move them if they are different. Thus you need to use 'fc'. No need for that - no mention was MADE about comparing files. I think we have different interpretations of the task. Quote from: foxidrive on June 10, 2014, 05:52:34 AM No need for that - no mention was made about comparing files. I think we have different interpretations of the task.I looked at it again, and can see where we interpreted things differently. |
|