Trim (or go up) one level of directory tree in powershell variable -
say have variable $source = "c:\temp\one\two\three"
, want set $destination
equal $destination = "c:\temp\one\two"
programmatically, how might it?
the best idea i've had trim that, there better way?
perhaps like
$source = "c:\temp\one\two\three" $dest = "..$source"
getting parent directoryinfo object, lee suggests, work. alternately, if prefer use more powershellesque commands opposed direct .net framework calls, can use powershell's built-in split-path cmdlet this:
$source = "c:\temp\one\two\three" $destination = split-path -path $source -parent # $destination string value "c:\temp\one\two"
Comments
Post a Comment