batch-file - 从批处理文件调用 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.
这是因为输出文件名周围有双引号。我该如何解决这个问题?
解决方案
正如其他人在评论中所建议的那样,您应该为您的任务使用标准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
。该术语0x22
是forfiles
特定的,并标记了文字引号。
推荐阅读
- python - 如何用 python-attrs 构造解决“意外的关键字参数”,让 mypy 开心?
- eclipse - 需要单击 Salesforce 中的“联系人”选项卡,出现错误“无法读取未定义的属性(读取 'defaultView')”
- python - 如果没有列名,如何提取值?
- java - 将接口转换为子接口
- r - 在 R 中保存在 forloop 中创建的具有不同名称的列表对象
- python - 打开文件时如何在pyinstaller中添加自己的图标
- javascript - JavaScript 和 HTML:相互重叠的音频
- dart - 为什么飞镖类型转换会影响原始转换变量
- r - 在 r 中过滤数据时导入 .tsv
- python - Python ctypes 错误:OSError: [WinError 193] %1 不是有效的 Win32 应用程序