[英]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.