views:

265

answers:

4

Visual studio 2005: I am moving from post build event to using the external tools menu with a batch file.

Previously I had

cd "$(ProjectDir).."
for /f "tokens=2,3,4 delims=/ " %%a in ('date /t') do set bdate=%%c.%%a.%%b
pkzipc -add -overwrite -dir=current "Z:\Technology\VisualStudio2005\Project Zips\$(ProjectName)_%bdate%_%username%.zip" "$(ProjectDir)*"

When I try to use this as an external tool it wraps "" around the projectname and adds an extra \ on SolutionDirectory (I am not sure if I want project or solution dir going forward, neither seems to be working)

The code I'm attempting to use:

pkzipc -add -overwrite -dir=current Z:\Technology\VisualStudio2005\Project Zips\%2\%2_%bdate%_%username%.zip %1*

this code doesn't work I think the first part stripping the outside "" is answered, which leaves the extra \ on the end of the projectdir variable. How can I fix that?

+1  A: 

I'm not sure I'm following you (and there's no direct question), but if you have a parameter surrounded by quotes and you want to drop them, you could use another variable:

set THEDIR=%1
set THEDIR=%THEDIR:"=%
JimG
haven't tested but sounds like that helps with the one argument, what about the extra \?My question is the code I'm attempting to use doesn't work because of these extra attachments to the data I need, and I am not familiar with dos/win batch files all that much.
Maslow
This is working ok in the command prompt, but because of other reasons in my question comment, the External Tools isn't doing what I believe I would need to achieve this.
Maslow
A: 

You can also trim the last char off like this:

SET SOMEVAR=%SOMEVAR:~0,-1%

If the quotes and the \ appear in the same variable, you could do this instead:

SET SOMEVAR=%SOMEVAR:~1,-2%
JimG
is there somewhere I could reference these commands for future use? I searched for dos batch files and could not find anything this detailed/complex.
Maslow
You can find the details on substrings and string replacement by running SET /?Other excellent sources for useful tricks are CMD /? and FOR /?
JimG
This appears to be working in the cmd prompt directly, but not in a batchfile linked via external tools in Visual Studio
Maslow
A: 

You probably setting the external tool wrong, you need to put full path to pkzipc in the Command: field, and put the arguments in the Arguments:.
Also you don't have access to script params so %1 %2 would not work, you argaument field should be then:

-add -overwrite -dir=current "Z:\..\$(ProjectName)_%bdate%_%username%.zip" "$(ProjectDir)*"
Shay Erlichmen
the command I have set is a batch file with this information in it, since %bdate% is not a real environment variable and would need to change daily.
Maslow
A: 

I wound up using a custom built .net application instead of the command line for this, since it was less complicated that way.

Maslow