You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改PowerShell脚本,为网络目录CSV清单添加文件/文件夹类型列

修改后的PowerShell脚本
$Directory ="X:\Sub\General"
Get-ChildItem -Path $Directory -Recurse -Force | ForEach {[PSCustomObject]@{
FullPath = $_.FullName  
FileName = $_.Name
Size = $_.Length
Extension = $_.Extension
Creation = $_.CreationTime
LastWriteTime = $_.LastWriteTime
ItemType = if ($_.PSIsContainer) { "文件夹" } else { "文件" }
}
} | Export-Csv -Path "C:\users\abc\Downloads\fulllist.csv" -NoTypeInformation
关键修改说明
  • 新增ItemType列,利用PowerShell内置的PSIsContainer属性判断条目类型:
    • 若$_.PSIsContainer为$true,则标记为文件夹
    • 若为$false,则标记为文件
  • 给Export-Csv添加-NoTypeInformation参数,避免CSV文件开头生成多余的类型注释行,让输出格式更简洁规范。

内容的提问来源于stack exchange,提问作者Dinesh Padmanabhan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 07:44:53