Call MSXSL from batch file

-1

I want to create a batch file that loops through a folder containing xml files, then call msxsl to modify them and after modify the xml file, copying to another folder with original filename.

I tried this:

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"

But that gives me this error:

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.

This is because of the double quotes around the output filname. How do I get around this?

batch-file
for-loop
msxsl
forfiles
asked on Stack Overflow Aug 19, 2019 by Quality • edited Aug 20, 2019 by aschipfl

1 Answer

1

As already suggested by others in comments, you should use a standard for loop for your task rather than 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"
)

But if you do insist on forfiles you could use the following code:

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"

The inner for loop together with the ~-modifier is used to get rid of the additional quotation marks around the file name returned by @file. The term 0x22 is forfiles-specific and marks a literal quotation mark.

answered on Stack Overflow Aug 20, 2019 by aschipfl

User contributions licensed under CC BY-SA 3.0