我编写脚本来获取目录,文件名和行数,但是当我导出到CSV时,我以null表结束。怎么了?
这是我写的代码:
Get-ChildItem C:\Users\bi\Desktop\MOMO_FILES -Include *.txt -Recurse
$result = % {
$_ | select CreationTime, DirectoryName, name, @{n="lines";e={
Get-Content $_ | Measure-Object -Line | select -expa lines
}}
}
$result | Export-Csv C:\Users\bi\Desktop\filename.csv -NoTypeInformation
答案 0 :(得分:0)
您的问题是您没有将Get-ChildItem
部分合并到您的管道中。你需要这样做:
$result = get-childitem C:\Users\bi\Desktop\MOMO_FILES -Include *.txt -recurse | % { $_ | select CreationTime, DirectoryName,name, @{n="lines";e={
get-content $_ |
measure-object -line |
select -expa lines }
}
}
$result | Export-csv C:\Users\bi\Desktop\filename.csv -NoTypeInformation
或者,如果您希望它稍微偏向水平,请将Get-ChildItem
结果发送到变量并使用:
$files = get-childitem C:\Users\bi\Desktop\MOMO_FILES -Include *.txt -recurse
$result = $files | % { $_ | select CreationTime, DirectoryName,name, @{n="lines";e={
get-content $_ |
measure-object -line |
select -expa lines }
}
}
$result | Export-csv C:\Users\bi\Desktop\filename.csv -NoTypeInformation