![](/img/trans.png)
[英]GlobalAddAtom() returns 0 and GetLastError = 0x5 on Win7, works on XP
[英]Batch script works in XP and not in Win7
利用這些論壇的知識,我編寫了一個有用的批處理腳本。
Del "- Output.tx_"
Del "- Output.txt"
FOR %%I in (*.txt) do @echo Filename: %%~nxI >>"- Output.tx_" & echo. >>"- Output.tx_" & echo. >>"- Output.tx_" & FOR %%f in (%%I) do type %%I >>"- Output.tx_" & echo. >>"- Output.tx_" & echo. >>"- Output.tx_"
TYPE "- Output.tx_" | MORE /E /P /S > "- Output.txt"
Del "- Output.tx_"
我的家用計算機具有XP(SP3,32位),並且腳本完美地結合了文本文件,如下所示。
Filename: Test1.txt
[Text file 1 contents]
Filename: Test2.txt
[Text file 2 contents]
... and so on.
但是,幾個月前,我已經在工作的計算機上運行了此腳本作為測試,但遇到了問題。 工作中的計算機具有Windows 7(32位SP1),並且僅將文本文件的標題合並到輸出文件中。 結果是:
Filename: Test1.txt
Filename: Test2.txt
... and so on.
對於使腳本在Windows 7上正常運行的任何評論或反饋,將不勝感激。
謝謝,
迪威克
我唯一能想到的是Win7計算機上的某些(或全部)文本文件中的名稱中包含空格或特殊字符,因此TYPE無法找到它們。 如果發生這種情況,應該有一條錯誤消息,但是它不在您的輸出文件中,因為您尚未重定向stderr。
可以通過引用變量來解決該問題。
您的代碼比需要的要復雜。 這是一個簡化的版本,具有相同的功能,但已解決了報價問題。 我還重定向了stderr。
@echo off
2>nul del "- Output.txt"
(
for %%F in (*.txt) do @(
echo Filename: %%F
echo.
echo.
type "%%F"
echo.
echo.
)
) | more /s /p >"- Output.tx_" 2>&1
move "- Output.tx_" "- Output.txt" >nul
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.