首先我正在过滤最新的文件:
#Copying with variable, get the latest file, descending take first, timestamp
$latestfile = gci -Attributes !Directory *.xml -Recurse -Force | Sort-Object -Descending -Property LastWriteTime | select -First 1
然后我需要 $latestfile 的上两层父文件夹(我还无法获取它:)
(Get-Item $latestfile).Directory.Parent.Parent.FullName```
It says: path doesnt exist
I am trying to get the second level higher path folder name, then take only the numerical part and add a 1, and then create a folder with that number.
为什么是
-Attributes !Directory
而不是-File
?另外:
$LatestFile = Get-ChildItem -File -Force -Recurse -Filter *.xml |
Sort-Object -Property LastWriteTime -Descending |
Select-Object -First 1
$GrandParentDirectory = $LatestFile.Directory.Parent.Parent
此时,您将
$GrandParentDirectory
作为 [DirectoryInfo]
对象,并且可以访问其 .FullName
和 .Name
属性来根据需要执行操作。