【问题标题】:Need Powershell script to list all files name with filesize in a directory and subdirecties需要 Powershell 脚本来列出目录和子目录中文件大小的所有文件名
【发布时间】:2017-12-04 00:36:51
【问题描述】:

以下脚本仅针对指定目录生成结果。我需要在目录和任何子目录中输出所有文件及其名称和大小:

Get-ChildItem -Path D:\Files\17-NRELBLD-02-P1.11\SERVICES\DCFORMS\ –Recurse -File |
    Select-Object Name,@{Name="MB";Expression={[math]::Round($_.Length/1kb)}} | 
    Export-Csv -NoTypeInformation -Path D:\Files\Vij\Result.csv 

【问题讨论】:

    标签: powershell csv


    【解决方案1】:

    您必须在 export-csv 中使用 -append 并且可以在 get-childitem 中使用通配符,例如:

    Get-ChildItem -Path D:\Files\17-NRELBLD-02-P1.11\SERVICES\DCFORMS\* –Recurse -File | 
    Select-Object Name,@{Name="MB";Expression={[math]::Round($_.Length/1kb)}}  | 
    Export-Csv -NoTypeInformation -Path D:\Files\Vij\Result.csv -Append
    

    【讨论】:

    • 您好 Ranadip,感谢您的回复,现在我收到此错误 • :术语“•”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。在 line:1 char:1 + • Get-ChildItem -Path D:\Files\17-NRELBLD-02-P1.11\SERVICES\DCFORMS* –Recurse - ... + ~~~~ + CategoryInfo : ObjectNotFound: ( •:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
    • @VijayanRavichandran:接受答案将是可观的。
    猜你喜欢
    • 1970-01-01
    • 2012-10-28
    • 2012-11-14
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    • 2012-09-02
    相关资源
    最近更新 更多