Using Split-Path to Retrieve the Parent Directory
To retrieve the parent directory from a file path, use the following PowerShell commands:
# Define the file path
$Variable = "c:\temp\fichier.log"
# Retrieve the parent directory
$Variable = $Variable | Split-Path
# Output the result
$Variable
In this example, the parent directory of c:\temp\fichier.log
is c:\temp
.
Example with Different Paths
You can apply the same command to different paths. Here is another example:
# Define the file path
$Variable = "c:\temp\exploit"
# Retrieve the parent directory
$Variable = $Variable | Split-Path
# Output the result
$Variable
In this case, the parent directory of c:\temp\exploit
is also c:\temp
.
0 Comments