[Show/Hide Left Column]

s_PerCentInScripts

Workaround for "%" in filenames

The Problem

In a batch file, %1 through %9 are replaced by the corresponding arguments on the command line.
ZTreeWin calls ZTW_MENU.BAT with no arguments on the command line, these are replaced by nothing!
Unfortunately these are valid componemts of a file name, which can become corrupted.
ZTreeWin 1.60.1 F9 now Passes %%1 etc. when invoking ZTW_MENU.BAT, so this is no longer needed, but does no harm.

Demonstration of Workaround for "%" in filenames

::Demonstration of Workaround for "%" in filenames
:: Purpose:         Workaround for "%" in filenames
:: Author:          Ian Binnie
:: Original author: Antti http://www.ztw3.com/archive/021/archive.cgi?read=82146
:: ZTW ver:         All
:: OS version:      All (I hope)
if NOT '%%1'=='' goto launch
call #ZTTemp\ztw_menu.bat %%%%%%%%1 %%%%%%%%2 %%%%%%%%3 %%%%%%%%4 %%%%%%%%5 %%%%%%%%6 %%%%%%%%7 %%%%%%%%8 %%%%%%%%9
goto :eof
:launch
Echo Your script here using ZTreeWin filespec '%1'
pause


How it works

When ZTreeWin creates ZTW_MENU.BAT Double percent signs (%%) are passed as a single percent sign (%). (See 3.4.1 Batch Parameters in the help file.)

When ZTreeWin calls ZTW_MENU.BAT with no arguments ('%%1'==''), the script recursively calls ZTW_MENU.BAT with 9 parameters %%%%1 through %%%%9.

This time, the first argument is not null, so your script is executed.

%1 through %9 in file names are replaced by the corresponding arguments on the command line i.e. %%1 through %%9.
When the script is executed these are interpreted as %1 through %9, restoring the original names.

If you have a filename containing %0, you are still out of luck!


Contributors to this page: ian .
Page last modified on Friday 25 of May, 2007 21:41:10 EDT by ian.