[英]powershell, write-host all filenames of the files
I am now better in writing, stealing and modifying scripts but here I am a stuck a little. 我现在在编写,窃取和修改脚本方面做得更好,但在这里我有点陷入困境。 My script sums up files in a specific folder and counts them. 我的脚本汇总了特定文件夹中的文件并对其进行了计数。 Like this : 像这样 :
{
function alljournals
{
$colItems = (get-childitem "$targetfolder" -include *.xlsx* -recurse | measure-object -property length -sum)
write-host "Collected all .xlsx files from all ImportJournal folders" -foregroundcolor "green"
"Number of files: "+ $colItems.count + [Environment]::NewLine + "Size of all files "+"{0:N2}" -f ($colItems.sum / 1MB) + " MB"
}
alljournals
}
What's the smartest way to list all files from that folder using write-host? 使用write-host列出该文件夹中所有文件的最智能方法是什么? I tried to put a write-host $colitems.Fullname without good results. 我试着写一个写主机$ colitems.Fullname而没有好的结果。
I know that I could easily put the files in a loop and than use foreach and display the filename. 我知道我可以轻松地将文件放在一个循环中,而不是使用foreach并显示文件名。 But for that I have to change everything. 但为此,我必须改变一切。 So is there a way? 那有办法吗?
Right now it displays something like that : 现在它显示的内容如下:
Collected all .xlsx files from all Importjournalfolders
Number of files 15
Size of all files: 13,3mb
What I need before that output is a list of all files with path 在输出之前我需要的是具有路径的所有文件的列表
Any Ideas or tips ? 任何想法或提示?
You could capture the list of files in the first pipeline using tee-object, and then use foreach on that. 您可以使用tee-object捕获第一个管道中的文件列表,然后使用foreach。
$colItems = (get-childitem "$targetfolder" -include *.xlsx* -recurse | tee-object -variable files | measure-object -property length -sum)
$files | foreach-object {write-host $_.FullName}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.