سؤال

I need a batch file to compare two lines, in two different files.

FILE1:

CONFIG1(TRUE / FALSE)
CONFIG2(TRUE / FALSE)
CONFIGFOCUS,99999,

FILE2:

CONFIG2(TRUE / FLASE)
CONFIG2(TRUE / FALSE)
CONFIGFOCUS,999999,

So what i would like to do, is a batch file that would check throught every INI files of many folders, and would compare the line of FILE1 'CONFIGFOCUS' and compare it with the config of FILE2 'CONFIGFOCUS'. And I would like it to check IF CONFIGFOCUS == '99999', change it for '999999'. for every INI files in different folders. IS this doable? If yes, could you please explain how? (i am a beginner in Batch file, and I would like to understand how to do it)

هل كانت مفيدة؟

المحلول

To change CONFIGFOCUS,99999, to CONFIGFOCUS,999999, in a tree of files, this should work:

This uses a helper batch file called repl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855

Put repl.bat in the same folder as the batch file, which is in the main folder of your tree of INI files.

@echo off
for /r %%a in (*.ini) do (
type "%%a" |repl.bat "CONFIGFOCUS,99999," "CONFIGFOCUS,999999," >"%%a.tmp"
move /y "%%a.tmp" "%%a" >nul
)

نصائح أخرى

@echo off &setlocal
set "startfolder=x:\inifiles"
:: change 'CONFIGFOCUS' from '99999' to '999999'
for /d /r "%startfolder%" %%a in (*) do sed -i.bak "/CONFIGFOCUS/Is/99999/999999/" "%%~a\*.ini"
:: list 'CONFIG1', 'CONFIG2' and 'CONFIGFOCUS' from all files to compare
for /d /r "%startfolder%" %%a in (*) do findstr /bic:"CONFIG1" /c:"CONFIG2" /c:"CONFIGFOCUS" "%%~a\*.ini"

sed for Windows

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top