If you want to do it in batch you can use this syntax instead. This just gives you the parent and Grandparent folder. If you need the full path to these then add the dp
modifiers to the FOR variable.
@echo off
For /f "skip=1 delims=" %%G IN ('WMIC service WHERE "name LIKE 'wdpostman'" GET PathName ^|findstr /r /V "^$"') DO (
for %%H in ("%%~dpG\.") do set "parent=%%~nxH"
for %%H in ("%%~dpG\..") do set "gparent=%%~nxH"
)
echo parent=%parent%
echo gparent=%gparent%
Just wanted to add this extra set of code to show you how you can break up the folder paths into variables.
@echo off
setlocal enabledelayedexpansion
For /f "skip=1 delims=" %%G IN ('WMIC service WHERE "name LIKE 'wdpostman'" GET PathName ^|findstr /r /V "^$"') DO (
set "_fpath=%%~dpG"
)
set "_fpath=%_fpath:~0,-1%"
set i=1
set "_spath!i!=%_fpath:\=" & set /A i+=1 & set "_spath!i!=%"
echo There %i% Folder(s^)
set _spath
Pause