Problem with substitution of FOR variable references

Hi,
I was trying to add a shell batch to a button that does various thing to automate my photo workflow and found out that substitution doesn't work with variables inside a FOR.

I've nailed down the thing to the following simple script (it can be simplified even more probably):

[code]@ECHO OFF

FOR /R %1 %%f IN (*.jpg) DO (

ECHO. 
ECHO Processing file %%f

SET destfname=%%~nf
ECHO Filename %destfname%

)
PAUSE[/code]

If you run it from an XP shell, passing a directory with JPG files in it, it will correctlly display both the full filename (with the path) and the stripped filename (without the path).

If you run it from a Dopus button it just prints out the first, thus %%f reference works correctly but the reference with the substitution %%~nf doesnt work.

Any idea on how to make it work?

How are you running the batch file from the button? Is the batch file itself in an Opus button with MS-DOS Batch Mode set as the type or is the batch file saved somewhere as a .bat that you're running from an Opus button?

Originally it was a batch file saved somewhere, executed from a command with MS-DOS Batch Mode set and the command was assigned to a button.

I tried also running it directly as a batch file from the button and running directly the code (copy&pasted) from the button.

The result is always the same: the script outputs the results for the variable reference %%f but not for the other one %%~nf.

It's very easy to test it: just save the code to a .bat file, setup a button with MS-DOS Batch Mode set where you invoke the batch passing {sourcepath$} as the parameter. Then run the same batch in a shell passing a directory.

Never mind,
I found out what was the problem: I forgot about delayed variable expansion. The following works correctly:

[code]@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /R %1 %%f IN (*.jpg) DO (

ECHO. 
ECHO Processing file %%f

SET destfname=%%~nf
ECHO Filename !destfname!

)
PAUSE
[/code]