0

Please keep in mind that I'm a newb.

I need to drag and drop 244 files with a .tex extension into a batch that then creates a .png that I can edit. Simply selecting them all and dropping them in isn't doing the trick, so someone wrote me a code that I have no idea how to properly use:

for %%f in (*.tex) do c:\python27\python.exe tools/textool.py -x -v -ra %%f

The .tex files are all in the same directory of the batch, which is in C:\users\myname\downloads\folder1\folder2\folder3. Hope you can help.

1 Answers1

0

Try this batch code:

@echo off
if "%~1" == "" goto :EOF
for %%I in ("%~1\*.tex") do C:\python27\python.exe "%~dp0tools\textool.py" -x -v -ra "%%~fI"

The batch file does nothing if called without a parameter.

But in case of batch file is called with a parameter, it expects without verification (could be added) that the (first) parameter specifies a folder path in which all *.tex files should be processed by the Python script.

An alternate solution:

@echo off
if "%~1" == "" goto :EOF
pushd "%~1"
if errorlevel 1 goto :EOF
for %%I in ("*.tex") do C:\python27\python.exe "%~dp0tools\textool.py" -x -v -ra "%%~nxI"
popd

The directory specified as parameter becomes the current working directory for this batch file and the Python script gets just file name with file extension passed via command line parameter.

For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.

  • call /? ... explains:
    • %~1 ... first parameter without surrounding double quotes
    • %~dp0 ... drive and path of argument 0 which is path of folder containing the batch file ending with a backslash.
  • echo /?
  • for /?
  • goto /?
  • if /?
  • popd /?
  • pushd /?

Note: It would be much faster to modify the Python script to search itself for all *.tex files in folder path specified on command line as parameter for conversion of each found file matching the pattern to a *.png file.

Mofi
  • 46,139
  • 17
  • 80
  • 143