首页 > 解决方案 > 从批处理文件调用 MSXSL

问题描述

我想创建一个循环遍历包含 xml 文件的文件夹的批处理文件,然后调用 msxsl 来修改它们,并在修改 xml 文件后,复制到具有原始文件名的另一个文件夹。

我试过这个:

forfiles /p C:\Users\mae\Documents\Testing\MSXSL\In /m *.xml /c "cmd /c C:\Users\mae\Documents\Testing\MSXSL\msxsl.exe @file pre-process_add_filename.xsl -o C:\Users\mae\Documents\Testing\MSXSL\Out\@file"

但这给了我这个错误:

Error occurred while creating file 'C:\Users\mae\Documents\Testing\MSXSL\Out\"bk_OIOUBLInvoice_TEST.xml"'.


Code:   0x8007007b
The filename, directory name, or volume label syntax is incorrect.

这是因为输出文件名周围有双引号。我该如何解决这个问题?

标签: batch-filefor-loopmsxslforfiles

解决方案


正如其他人在评论中所建议的那样,您应该为您的任务使用标准for循环,而不是forfiles

for %%I in ("%UserProfile%\Documents\Testing\MSXSL\In\*.xml") do (
    "%UserProfile%\Documents\Testing\MSXSL\msxsl.exe" "%%I" "pre-process_add_filename.xsl" -o "%UserProfile%\Documents\Testing\MSXSL\Out\%%~nxI"
)

但是如果你坚持forfiles你可以使用下面的代码:

forfiles /P "%UserProfile%\Documents\Testing\MSXSL\In" /M "*.xml" /C "cmd /C for %%I in (@file) do 0x22%UserProfile%\Documents\Testing\MSXSL\msxsl.exe0x22 @file 0x22pre-process_add_filename.xsl0x22 -o 0x22%UserProfile%\Documents\Testing\MSXSL\Out\%%~I0x22"

内部for循环与~-modifier一起用于去掉 . 返回的文件名周围的附加引号@file。该术语0x22forfiles特定的,并标记了文字引号。


推荐阅读