2014-07-01 84 views
0

我嘗試編寫一個批解析文件的批處理文件,以創建另一個包含其內容的文件。 但是在新版本中,我會忽略以-Dremote模式開頭的每一行。逐行讀取文件並忽略它們中的一部分

這裏是我的文件

-nl 
fr_yy 
-clean 
-vmargs 
-Dgma.environnement=staging 
-Duser.timezone=CET 
-Dgma.communication=remote 
-Dgma.security.disable=false 
-Xms256M 
-Xmx768M 
-XX:PermSize=64m 
-XX:MaxPermSize=128m 
-Dlogback.configurationFile=file:eclipse/conf-log/logback-error.xml 
-Dshut.monitor.active=true 
-Dshut.monitor.home=\\mynas05\GMData\Projets\RefonteUtilisateurs\Contrats\shut 
-Dshut.applicationRuntimeEnv.systemPropertyKey=gma.environnement-nl 
-Dremote_server_MessageWar=http://xxx.xxx.yy 
-Dremote_port_MessageWar=40110 
-Dremote_server_SinistreWar=http://xxx.xxx.yy 
-Dremote_port_SinistreWar=40110 
-Dremote_server_FacturationTiersWar=http://xxx.xxx.yy 

這裏是代碼

for /f "tokens=*" %%A in (%tempFile%) do (
    set test=%%A 
    IF NOT "!test:~0,7!"=="-Dremote"(type %%i>>%iniFile%) 
) 

但一切都在ini文件複製...

+0

如果你需要幫助,給我們所有的代碼,不只是一個部分,我們不知道什麼%% i定義爲,或者如果你已經推遲啓用擴展,等等......還,既提供答案做你說你想要的東西,但是你不想要的東西,所以請重申你想要的,並給出例子輸入和輸出文件。 – nephi12

回答

1

在一行中有幾個錯誤。試試這個:

IF NOT "!test:~0,8!"=="-Dremote" (echo %%A>>%iniFile%) 
  1. 你算錯(-Dremote有8個字符,而不是7)。
  2. 使用echo而不是type
  3. 錯誤的位置有一個空間。
  4. 使用錯誤的變量。

(我希望你知道,你將不得不使用延遲擴展(這是不是在你的代碼)。)

+0

謝謝!它工作的很好!我不得不改變%tempFile%在循環中,我不得不改變它的文件名。使用變量它不工作... – bryce

+0

它應該工作正常,如果%tempFile%正確設置... – Stephan

+0

我這樣設置:設置tempFile =「eclipse \ tmp.ini」 有什麼問題嗎? – bryce

0

快速編輯應該修復它:

for /f "tokens=*" %%A in (%tempFile%) do (
    set test=%%A 
    IF NOT "!test:~0,7!"=="-Dremote"(echo !test!>>%iniFile%) 
) 
+0

感謝您的幫助,但它只寫入文件名,而不是內容...... – bryce

2
findstr /v /b /l /c:"-Dremote" "%tempFile%" >"%iniFile%" 

(首先測試虛擬%iniFile% ......)

+0

如果可能,您應該避免編寫全新的代碼,這不是一個代碼編寫服務,如果我們可以修改OP的代碼而不是最好的從頭開始。 – nephi12

+0

對不起,但它不起作用... :-( – bryce

+0

@bryce是的,它可以處理你提供的數據 – foxidrive

0

更改爲7〜8「-Dremote」有8個字符。
在圓括號之前的「-Dremote」之後添加一個空格。

setlocal enabledelayedexpansion 

for /f "tokens=*" %%A in (%tempFile%) do (
set test=%%A 
IF NOT "!test:~0,8!"=="-Dremote" (echo !test!>>%iniFile%) 
)