[英]is there a way to return last file in the subfolders when using PowerShell
I have PowerShell script and i want to return multiple folders based on their positional using a wile card ex.我有 PowerShell 脚本,我想使用一个诡计卡 ex 根据它们的位置返回多个文件夹。 sqlfile*\table i get-childitems -recurse.
sqlfile*\table 我得到-childitems -recurse。 Thank you
谢谢
"I want to return the newest and last file which is in the end of the last subfolder."
“我想返回最后一个子文件夹末尾的最新和最后一个文件。”
Is this what you are going for based on your comment above?根据您上面的评论,这是您想要的吗?
Get-ChildItem -Recurse -Path D:\Temp -Directory
# Results
<#
Directory: D:\Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 06-May-20 20:30 AddressFiles
d----- 17-Feb-20 15:50 est
d----- 14-Mar-20 17:03 here
d----- 26-May-20 10:38 hold
d----- 06-May-20 20:30 LogFiles
d----- 06-Feb-20 14:56 NewFolder
d----- 12-Feb-20 14:24 ParentFolder
d----- 03-Feb-20 11:55 Reference
d----- 06-Feb-20 14:56 Source
d----- 24-Feb-20 22:03 Target
d----- 22-May-20 20:51 Zips
Directory: D:\Temp\NewFolder
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 03-Feb-20 11:55 New folder
d----- 20-Jan-20 11:17 temp
Directory: D:\Temp\ParentFolder
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 12-Feb-20 14:08 ChildFolder
Directory: D:\Temp\ParentFolder\ChildFolder
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 12-Feb-20 14:08 GrandchildFolder
#>
Get-ChildItem -Recurse -Path D:\Temp -Directory |
Select-Object -Last 1
# Results
<#
Directory: D:\Temp\ParentFolder\ChildFolder
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 12-Feb-20 14:08 GrandchildFolder
#>
(Get-ChildItem -Recurse -Path D:\Temp -Directory |
Select-Object -Last 1).Fullname
# Results
<#
D:\Temp\ParentFolder\ChildFolder\GrandchildFolder
#>
$LastSubFolder = (Get-ChildItem -Recurse -Path D:\Temp -Directory |
Select-Object -Last 1).Fullname
Get-ChildItem -Path $LastSubFolder
# Results
<#
Directory: D:\Temp\ParentFolder\ChildFolder\GrandchildFolder
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 28-Aug-07 13:08 2646058 GrandchildThumperLong.wav
-a---- 28-Aug-07 13:05 683670 GrandchildThumperShort.wav
-a---- 23-Apr-99 18:22 668440 GrandchildWELCOM98.WAV
#>
Get-ChildItem -Path $LastSubFolder | Sort-Object -Property LastWriteTime
# Results
<#
Directory: D:\Temp\ParentFolder\ChildFolder\GrandchildFolder
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 23-Apr-99 18:22 668440 GrandchildWELCOM98.WAV
-a---- 28-Aug-07 13:05 683670 GrandchildThumperShort.wav
-a---- 28-Aug-07 13:08 2646058 GrandchildThumperLong.wav
#>
Get-ChildItem -Path $LastSubFolder | Sort-Object -Property LastWriteTime |
Select-Object -First 1 -Last 1
# Results
<#
Directory: D:\Temp\ParentFolder\ChildFolder\GrandchildFolder
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 23-Apr-99 18:22 668440 GrandchildWELCOM98.WAV
-a---- 28-Aug-07 13:08 2646058 GrandchildThumperLong.wav
#>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.