2012-07-23 112 views
0

我已經創建了一個腳本,並希望它循環遍歷目錄中的所有文件.. 但我沒有做到這一點.. 我創建了另一個腳本來應用腳本(change_content).. 這裏的代碼,批處理文件循環遍歷文件夾中的每個文件

cd \input 

for %%f in (*.txt) do (

      echo "%%~nf" 
      "D:\deployment code\change_content" .\"%%~nf".txt 
    ) 

change_content.bat

call :yesterday today -1 
for /f "delims=" %%a in (%1) do (
set "val=%%a" 
if "!val:~12,10!"=="0001-01-01" (
>> D:\temp\%1_changed.txt echo !val:~0,12!%day%!val:~22! 
) else (
>> D:\temp\%1_changed.txtecho %%a  
) 
) 

我的問題是我不能讓腳本讀取輸入文件,如果我把它作爲變量。我只能把實際的文件放在自動化的過程中嗎? 這只是其中i指向輸入和輸出方向的部分代碼.. 只是想知道我應該怎麼辦在FOR/F的地方..

將不勝感激,如果有人可以幫助這個..謝謝:)

+0

安裝Cygwin。使用bash。你會更快樂...... – EdH 2012-07-23 02:02:21

回答

1

我明白你的問題,你以上面的粗體文字列出。下面的內容應該起作用,從內存中進行,但現在我無法測試它,因爲我現在沒有Windows計算機(並且很高興我不必與我一起)。

如果您在主程序中循環部分instersted,試試這個:

setlocal eneabledelayedexpansion 

REM:: take \input as param from command line 
set top_folder=%~1 
set change_content="D:\deployment code\change_content.bat" 

for /f "eol=; tokens=1 delims=" %%t in ('dir /b !top_folder!\*.txt') do (
    REM:: the /b may or may not give yo the full path you need 
    REM:: google this if I am wrong 

    set file_name=%%~nt 
    !change_content! !file_name! 

) 

如果你有興趣在change_content部分,試試這個:

setlocal enabledelayedexpansion 

REM:: change_content looping over file_name variable. 
set file_name=%~1 
for /f "eol=; tokens=1 delims=" %%f in ('type "!file_name!"') do (
    set line=%%f 
    REM:: Do your thang in here with !line!. 
) 
+0

謝謝!它的工作..偉大〜 – cheeseng 2012-07-23 03:23:25

+0

np。很高興它的工作:) – kikuchiyo 2012-07-23 03:28:50

+0

讓我知道,如果我在你最後的評論後添加的內容是沒有必要的,我可以回覆你接受時的結果。 (在我提交最後一次編輯之前我沒有看到接受)。謝謝:) – kikuchiyo 2012-07-23 03:30:13

相關問題