How to step backwards in a path using Powershell

Viewed 7834

I am searching through folders in order to find the one that has the contents that I desire.

$path = dir "C:\windows\ccmcache\*\Office.en-us" -Directory
echo $path

It returns:

Directory: C:\windows\ccmcache\c

But when I run my command:

Start-Process "$path\setup.exe /uninstall ProPlus /config Uninstall.xml" -Wait

It tries to run:

C:\windows\ccmcache\c\Office.en-us\setup.exe............

Which doesn't exist! So how can I go back a step so I can run the setup.exe command out of the c folder? Something like:

$path2 = $path\cd..

Thank you all in advance.

4 Answers

It can be done simply using Resolve-Path function. suppose structure is like following

              root
      Folder1      Folder2

and our current working directory is Folder1 and we want to move to Folder2.

$path2 = Resolve-Path("$path\..\Folder2\fileinFolder2")
Related