1
votes

I just created the following batch file which saves all my lyx documents as tex files:

cd /d "D:\"
:: if the "for"-command is executed from the command line, just use "%" rather than "%%"
for /R %%g in (*.lyx) do "C:\Program Files (x86)\LyX 2.1\bin\lyx.exe" --force-overwrite --export pdflatex "%%g"

The problem is now that instead of the *.lyx files the batch uses the *.lyx~ files which are as far as I know some kind of backup files and don't contain the latest content.

How can I modify the batch file such that it takes the *lyx files rather than the *.lyx~ files?

Any suggestion would be great help.

Best :-)

PS: If I type this code in the command line (without using the batch), everything is fine.

1
Are you saying that it processes the .lyx~ files only (leaving the .lyx files out)? On my machine(W7 x64) it processes all of them (from batch and cmdline).CristiFati
Right, the resulting tex file contains not what is in the *.lyx files but what is stored in the *.lyx~ files ....Fabian
For replication: I create a lyx file with, say the conten "old", then create the tex file with the batch, then change the lyx content to "new" and run the batch again. The tex file is not updated and still contains "old", just as is contained by the lyx~ file ...Fabian
Does it work when you just double-quote the set parameter of for, like for /R %%g in ("*.lyx") do ? (maybe then it might be required to use "%%~g" instead of "%%g" in the body of for)aschipfl

1 Answers

0
votes

@Edit1: added tokens option. Now it works in subdirs with spaces.

Modify your for loop to:

for /F "tokens=*" %%g in ('dir /b /s *.lyx') do if "%%~xg" equ ".lyx" (
    "C:\Program Files (x86)\LyX 2.1\bin\lyx.exe" --force-overwrite --export pdflatex "%%g"
)

Another solution would be to use forfiles.

As for the 3rd comment, I think it does both but it does the .lyx~ at the end.

To see the output of a batch file simply launch it from a cmd window.