views:

267

answers:

2

On windows, I'm trying to acquire the file name using the %~f1 parameter.

I'm doing this from a new voice (command) which I've added to the contextual menu.

In the windows registry, the voice simply calls a batch script which prints the file name, by this way:

`C:\script.bat %~f1`

but I get this output:

`C:\Documents and Settings\Administrator\Desktop\%~f1`

so, the path is ok, but what about the filename?!

Suggestions? Thanks!

A: 

Try enclosing the entire variable in %'s.

C:\script.bat %~f1%

Antonio Haley
+2  A: 

When the context menu item it triggered, it is done so by Explorer (not cmd.exe) and Explorer does not implement %~f1. Hence you get the current result.

What you need is to modify your script so it receives the whole filename (you would probably put only 'C:\script.bat %1' or 'C:\script.bat' in the registry) and update your script to use %~f1:

@echo first argument: %1
@echo filename only: %~f1
@notepad %~f1

Good luck with that!

Philippe Payant
You'll might want to enclose the argument in quotes like 'C:\script.bat "%1"' if you're calling it directly, otherwise spaces in the filename might mess things up too.
lc
solved using 'C:\script.bat "%1", many thanks :)
Giancarlo