![](/img/trans.png)
[英]Rename bulk files with given name, in directory and subfolders using PowerShell
[英]PowerShell: Count files in a given name directory and subfolders
我需要計算給定文件夾中的文件
例子:
Folder A
Folder B
Folder C
對於每個文件夾,我需要計算有多少文件,最后計算總數。
最好的方法是什么?
標記到@Esperento57: ,有用的答案。
是的,它確實有效,但如果文件夾路徑沒有文件,它也會出錯; 而在混合中使用Measure-Object
可以解決這個問題。
$DirList = @('D:\Temp\AddressFiles',
'D:\Temp\BonoboGitServer',
'D:\Temp\Book'
)
$DirList |
ForEach-Object {
[pscustomobject]@{
Dirname = $PSItem
NbFile = (Get-ChildItem -Path $PSItem -File).Count
}
}
# Results
<#
Dirname NbFile
------- ------
D:\Temp\AddressFiles 3
The property 'Count' cannot be found on this object. Verify that the property exists.
At line:8 char:5
+ [pscustomobject]@{
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], PropertyNotFoundException
+ FullyQualifiedErrorId : PropertyNotFoundStrict
D:\Temp\Book 4
#>
而使用Measure-Object
cmdlet 可以解決問題......
$DirList = @('D:\Temp\AddressFiles',
'D:\Temp\BonoboGitServer',
'D:\Temp\Book'
)
$DirList |
ForEach-Object {
[pscustomobject]@{
Dirname = $PSItem
NbFile = (Get-ChildItem -Path $PSItem -File |
Measure-Object).Count
}
}
# Results
<#
Dirname NbFile
------- ------
D:\Temp\AddressFiles 3
D:\Temp\BonoboGitServer 0
D:\Temp\Book 4
#>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.