S
S
soulyaris2021-11-29 04:33:14
PowerShell
soulyaris, 2021-11-29 04:33:14

How to get only the parent directory of a file without the full path?

Good afternoon.
There is a search for files by creation time through GCI.

GCI -Path $Path | Where-Object {$_.CreationTime -LT $СheckTime}

If you fasten to this Split-Path
GCI -Path $Path | Where-Object {$_.CreationTime -LT $СheckTime}|Split-Path -parent

full paths are displayed (yes, you can turn off the disk from the path, but there is a long structure, it will not help).
You must then get the extreme single parent directories of these files without absolute paths without using text variable editing in the script body.
From the conditional C:\1\2\3\fi.le get 3. Is there such an option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2021-11-29
@soulyaris

C:\1\2\3\fi.le |Split-Path -parent |Split-Path -leaf

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question