Expand Parameter Extension

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Expand Parameter Extension

#1 Post by darioit » 09 Sep 2014 01:55

Hello,
I try to expand variable %TEMP% only with Path %~p but doesn't work, could you please help me.

Here my code:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem My script will start from this path %SCRIPTS%

set ORIGIN=%~d0\Home
set SCRIPTS=%ORIGIN%\Scripts
set INPUT=%ORIGIN%\Input
set OUTPUT=%ORIGIN%\Output
set ENVELOPE=%ORIGIN%\Envelope
set TEMP=%ORIGIN%\Temp

rem My command must be like this, because I want in a zip file also a name of directory
7za a %OUTPUT%\filezip.7z temp\a.pdf Temp\a.txt

rem But if I run this script a variable %Temp% will be resolved as "C:\Home\Temp" and this is not good
rem I try to expand %Temp% as %~p%Temp% but return alway a syntax error

rem This is a result that I don't want
7za a %OUTPUT%\filezip.7z %Temp%\a.pdf %Temp%\a.txt
7za a C:\Home\Output\filezip.7z C:\Home\Output\Temp\a.pdf C:\Home\Output\Temp\a.txt

rem This is a command I want, and also this must be run from directory %ORIGIN%, because if I run into %SCRIPTS% doesn't work
7za a C:\Home\Output\filezip.7z Temp\a.pdf Temp\a.txt



Thanks in advance and regards

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Expand Parameter Extension

#2 Post by Squashman » 09 Sep 2014 06:18

Not really making sense what you are trying to do. It looks like you are trying to use the command modifiers to get the path only from the TEMP variable. The command modifiers only work with the TOKEN variables within the FOR command and when an argument is passed to a batch file from the command line.

So essentially what you are trying to do is:

Code: Select all

H:\>echo %temp%
C:\Users\Squashman\AppData\Local\Temp

H:\>for /F "delims=" %G in ("%temp%") do echo %~pG

H:\>echo \Users\gcljf0\AppData\Local\
\Users\Squashman\AppData\Local\

Remember to double the percent symbol inside a batch file for the TOKEN variable.

Post Reply