1

My goal is to convert some files with *.cdr extension to *.ai in a directory. The files look like file_a.cdr. file_b.cdr ...... I have replaced the convert.exe for you to another simple command like copy, so don't ask about the sense here in my example.

    setlocal enableDelayedExpansion
    for %%f in (*.cdr) do (
    set "infile=%%f"
    set "outfile=%%~nf.ai"
    copy "%infile%" "%outfile%"
    )

The output of the batch is always different!!!!

Sometimes it is:

copy "%file_a.cdr" "%file_a.ai" => system cannot find file

or

copy "" "" => system cannot find file

I have already used this syntax copy !infile! !outfile! with now success:

Thx in advance

2 Answers 2

4

You don't need the variables

for %%f in (*.cdr) do (
    convert "%%f" "%%~nf.ai"
)

Or, if you are trying to do it from command line,

for %f in (*.cdr) do convert "%f" "%~nf.ai"

as inside batch files percent signs need to be escaped, but this is not the case for command line.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah, I understand now what the 'convert.exe' phrase was about.
This is the right answer. Accepting Answers.
0

Use delayed expansion. And surround your variables by ! instead of %

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.