Batch-program launchs with 1 parameter (full path to file)

program.cmd "C:\Path\To\File\Filename.txt"

Now, this program consists of 1 command:

echo %1

And it just prints an argument: C:\Path\To\File\Filename.txt for the upper example.

But I want it to print an argument (full path) with another extension, e.g. .exe. For the upper example, I want it to print C:\Path\To\File\Filename.exe.

How to make it do that?

link|improve this question

69% accept rate
feedback

2 Answers

up vote 2 down vote accepted
%~dpn1.exe
link|improve this answer
2  
This answer works, but it's not particularly descriptive. Use of the tilde magic variables would be echo %dpn1.ext you could also do echo %dpn1.%2 and then use changeext.bat foo.txt bar and have the output foo.bar see: technet.microsoft.com/en-us/library/bb490909.aspx for magic variable references. – Tyler Apr 17 '10 at 23:48
feedback

In your program.cmd, you can just write commands as you would normally use them at the command prompt.

link|improve this answer
Please, read again, I tried to explain more clearly. – Semyon Perepelitsa Apr 17 '10 at 11:43
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.