You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

批处理调用MSXSL处理XML时输出文件名带双引号报错如何解决?

Fix for Quoted Filename Error in forfiles + msxsl Command

The root issue here is that forfiles's @file variable automatically wraps the filename in double quotes. When you plug this directly into your output path, you end up with nested quotes (like Out\"bk_OIOUBLInvoice_TEST.xml\"), which Windows interprets as invalid syntax.

Here are two straightforward fixes, with the first being the simplest and most reliable:

1. Use @fname and @ext to Build a Quote-Free Filename

Instead of using @file for the output filename, split it into the base name (@fname) and extension (@ext). These variables don't include quotes, so your output path will be clean:

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\@fname.@ext"

This works because @fname gives you the filename without the extension (e.g., bk_OIOUBLInvoice_TEST) and @ext gives you just the extension (e.g., .xml). Combining them gives you the full, unquoted filename for the output path.

2. Strip Quotes from @file Using Delayed Expansion

If you prefer to stick with @file, you can remove the surrounding quotes using delayed variable expansion in cmd. This requires enabling delayed expansion (/v:on) and escaping the quote characters properly:

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

The set ""fn=!fn:\""""=""! part replaces the double quotes in the @file value with nothing, leaving you with the raw filename.

Either approach will resolve the "invalid syntax" error by ensuring your output filename doesn't have unwanted nested quotes.

内容的提问来源于stack exchange,提问作者Quality

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:07:13