2

My batch scripts are located in the following directory:

\\test\public\windows\scripts\32\test.bat

I'm trying to get the path of this folder: \test\public\windows\logs I've tried using %~dp0 in order to get the path of the script, and i've tried:

SET REL_PATH=..\..\

The thing is that it's not showing me this folder.

Alex Brodov
  • 3,365
  • 18
  • 43
  • 66

2 Answers2

2
SET REL_PATH=..\..\

path points to the path according to you, to verify where it is taking from, please make a

echo %CD%

it will tell you the path the system is looking at.

then set the relative path from %CD% to the path of your script.

Please comment if you get stuck after doing this.

For example:

echo %CD%

gives C:\windows\system32

and you want to execute batch file at c:\test\public\windows\scripts\32\test.bat

you will need to do

SET REL_PATH=%CD%\..\..\test\public\windows\scripts\32\

To move to this path do a:

cd /d %REL_PATH%

To solve UNC path do PUSHD and POPD:

@echo off
pushd \\test\public\windows\scripts\32\

REM do your work
call test.bat

popd

Reference: How to run batch file from network share without "UNC path are not supported" message?

Dai
  • 141,631
  • 28
  • 261
  • 374
1

Use the PUSHD command when working with network drives. This will assign an unused drive letter to the UNC path so you can navigate it like normal. Then you can use POPD to release it.

For example:

@ECHO OFF

PUSHD "\\test\public\windows\scripts\32"

REM This will be \\test\public\windows
DIR ".\..\..\"

POPD
Jason Faulkner
  • 6,378
  • 2
  • 28
  • 33