Strange prob with %@replace..

Hi,

I am working on a small script which is supposed to launch the PHP-File I am working in my webbrowser (after copying it to a temp-dir, if so required). In order to translate "local directory-separators" (\) into "web-friendly dir-separators" (/), I am using %@replace[^\,^/,%fp] - but unfortunately, when applied in a BTM, this empties the variable (whereas it works as expected when executing an echo of that on the command-line). (I am using TC 13 and have also tasted this against 15).

Where is the bug that I do not see?
usage: launch_php.btm c:\xampp\htdocs\foo.php


rem @echo off
ver
set fn=%@full[%1]
iff "%@ext[%fn]"=="php" then
set fp=%@path[%fn]
set fpu=%@upper[%fp]
set i=%@index[%fp,C:\XAMPP\HTDOCS\]
iff %i lt 0 then
set newnam =c:\xampp\htdocs\tmp\%@filename[%fn]
copy %fn %newnam
set fp=%@path["%newnam%"]
set fn=%newnam%
endiff

set relpth = %@instr[16,,%fn]
echo relpth=%relpth
echo repl1=%@replace[^\,^/,%relpth]
echo repl2=%@replace[^\,^/,"%relpth"]
echo repl3=%@replace[^\,^/,%relpth%]
rem ^^^^THIS KILLS "relpth" ^^^

echo Calling: http://localhost/xampp/%relpth
pause

http://localhost/xampp/%relpth
else
echo Only supporting PHP-Files currently!
endiff
 

samintz

Scott Mintz
May 20, 2008
1,503
16
Solon, OH, USA
You shouldn't need the escape characters before the slashes in your @replace calls.
Also there are 2 places in your script where you have spaces before and after the equals sign. SET is very specific about that sort of thing.
Code:
set newnam =c:\xampp\htdocs\tmp\%@filename[%fn]
          ^extra space
set relpth = %@instr[16,,%fn]
          ^ ^extra spaces

So change your script to:
Code:
rem @echo off
ver
set fn=%@full[%1]
iff "%@ext[%fn]"=="php" then
set fp=%@path[%fn]
set fpu=%@upper[%fp]
set i=%@index[%fp,C:\XAMPP\HTDOCS\]
iff %i lt 0 then
set newnam=c:\xampp\htdocs\tmp\%@filename[%fn]
copy %fn %newnam
set fp=%@path["%newnam%"]
set fn=%newnam%
endiff
 
set relpth=%@instr[16,,%fn]
echo relpth=%@replace[\,/,%relpth]
 
echo Calling: http://localhost/xampp/%relpth
pause
 
http://localhost/xampp/%relpth
else 
echo Only supporting PHP-Files currently!
endiff
 
May 20, 2008
3,515
4
Elkridge, MD, USA
Some more simplification possibilities:
1/ All string handling, including the variable function @INDEX, are case insensitive, unless explicitly stated. @REPLACE is one of the few exceptions - it is case sensitive. You can just use variable fp instead of fpu.
2/ You can compound functions, e.g., %@replace[\,/,%@replace[c:\xampp\htdocs\,,%fn]] - but it is more difficult to debug. Note that I used @REPLACE to strip part of the path, eliminating the need to count characters; even better that path string could be put into a variable, making the whole procedure more flexible.

But it works - you might as well leave it as is, and ignore my post.
 
Similar threads
Thread starter Title Forum Replies Date
R strange bug? Support 7
Jesse Heines Strange Line Wrapping Behavior Support 14
F strange results Support 9
M Strange error messages from TCC in FTP copy Support 7
M Another possibly strange remote registry issue Support 5
forbin Strange handling of [nonbright] magenta background (v22) Support 2
N Fixed Strange dir behavior Support 6
vefatica REGDIR, strange error message Support 7
T WAD Strange Unexpected "features" in the Debugger Support 2
P Strange mouse behavior with list Support 2
vefatica Strange tcc.exception.log Support 7
vefatica A strange one Support 0
D Strange DO behavior with /O Support 5
Glenn Bowes Strange text at startup Support 5
Steve Pitts WAD Strange output from DEL of a non-existent directory Support 7
vefatica Big numbers, strange errors Support 1
aedthuio Strange... lpksetup Support 4
CWBillow dir /4 strange Support 2
D Strange issue with FOR loop Support 15
vefatica OT: strange files in %TEMP Support 10
Dan Glynhampton Documentation v15 help: Strange links in @INT topic Support 0
R WAD Strange output from "memory" command Support 1
M Yet another strange something re something called "@TCONVERT" Support 8
Roedy How to? Strange colours Support 9
M WAD Strange "Start" misbehavior... Support 10
vefatica Very strange console font corruption Support 3
Steve Pitts Strange problem with FREE Support 10
A strange error in alias Support 9
newgeekorder Debugger IDE - strange tab and parameter behaviour Support 1
Exolon Strange Prompt. Support 6
vefatica Strange folders Support 1
T Strange CPU value Support 3
J Strange error: unset /s Support 14
M Strange behavior... Support 2
CWBillow Strange happenings Support 2
B Strange handling of a .BAT file Support 5
vefatica Strange behavior reloading SHRALIAS sav files. Support 1
J ASSOC / FTYPE strange error message Support 3
D Strange crashes in @CRC32 and @MD5 Support 9
Charles Dye Strange output, here-doc redirection, TYPE, //UnicodeOutput=Yes Support 6
S Strange CHKDSK behavior Support 6
vefatica Strange results with CP 1252 Support 12
S Strange REN problem - non-English characters Support 3
dcantor Strange status in ACTIVATE command Support 0
Joe Caverly Documentation Replace internal command with LIBRARY command Support 0
I how to make TCC default/replace cmd.exe? Support 9
x13 TPIPE /REPLACE - Remove line (including EOL) Support 3
T @replace -- what is wrong here Support 2
C Replace 1st argument on command line Support 4
R How to? Replace in Rename Support 9

Similar threads