As in a batch file set variable level up

I need in a batch file set above the path level. For example, I have the following folder structure:

C: \ Temp \ Script

In this script my batch file exists:

SET mypath=%~dp0 :: Set path C:\Temp\Script
SET UpLevel="%mypath:~0,-1%.."
echo UpLevel ::need show C:\Temp\

      

So how does he write?

+3


source to share


1 answer


@echo off

for /f "tokens=* delims=" %%a in ("%cd%") do echo %%~dpa 

      

or

@echo off

pushd ..
set "uplevel=%cd%"
popd

echo %uplevel%

      



or

@echo off
echo %~dp0
set "_path_=%~dp0"
set _path_=%_path_:~0,-1%

for /f "tokens=* delims=" %%a in ("%_path_%") do echo %%~dpa

      

?

+4


source







All Articles