Powershell Get-ChildItem 进度问题

发布于 2024-11-04 15:45:10 字数 1045 浏览 6 评论 0原文

所以,我在一个文件夹中有一组目录 00-99。每个目录都有 100 个子目录,00-99。每个子目录都有数千张图像。

我想做的基本上是在计算平均文件大小时获得进度报告,但我无法让它发挥作用。这是我当前的查询:

get-childitem <MyPath> -recurse -filter *.jpeg
| Where-Object { Write-Progress "Examining File $($_.Fullname)" true }
| measure-object -Property length -Average

这向我显示了一个随着每个文件的处理而更新的栏,但最后我没有返回平均文件大小数据。显然,我做错了什么,因为我认为尝试破解Where-Object来打印进度语句可能是一个坏主意(tm)。

由于有数以百万计的图像,这个查询显然需要很长时间才能完成。如果我理解正确的话, get-childitem 几乎将占据查询时间的大部分。有什么指示可以得到我想要的东西吗? AKA,我的结果理想情况下是:

Starting...
Examining File: \00\00\Sample.jpeg
Examining File: \00\00\Sample2.jpeg
Examining File: \00\00\Sample3.jpeg
Examining File: \00\00\Sample4.jpeg
...
Examining File: \99\99\Sample9999.jpg
Average File Size: 12345678.244567

编辑:我可以做一个简单的选择:

get-childitem <MyPath> -recurse -filter *.jpeg
| measure-object -Property length -Average

然后离开我的工作站一天半或其他时间,但这似乎有点低效=/

So, I've got a set of directories 00-99 in a folder. Each of those directories has 100 subdirectories, 00-99. Each of those subdirectories has thousands of images.

What I'm attempting to do is basically get a progress report while it's computing the average file size, but I can't get that to work. Here's my current query:

get-childitem <MyPath> -recurse -filter *.jpeg
| Where-Object { Write-Progress "Examining File $($_.Fullname)" true }
| measure-object -Property length -Average

This shows me a bar that updates as each of the files gets processed, but at the end I get back no average file size data. Clearly, I'm doing something wrong, because I figure trying to hack the Where-Object to print a progress statement is probably a bad idea(tm).

Since there are millions and millions of images, this query obviously takes a VERY LONG time to work. get-childitem is pretty much going to be the bulk of query time, if I understand things correctly. Any pointers to get what I want? AKA, my result would ideally be:

Starting...
Examining File: \00\00\Sample.jpeg
Examining File: \00\00\Sample2.jpeg
Examining File: \00\00\Sample3.jpeg
Examining File: \00\00\Sample4.jpeg
...
Examining File: \99\99\Sample9999.jpg
Average File Size: 12345678.244567

Edit: I can do the simple option of:

get-childitem <MyPath> -recurse -filter *.jpeg
| measure-object -Property length -Average

And then just walk away from my workstation for a day and half or something, but that seems a bit inefficient =/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吻安 2024-11-11 15:45:11

像这样的东西吗?

get-childitem -recurse -filter *.exe | 
      %{Write-Host Examining file: $_.fullname; $_} | 
      measure-object -Property length -Average

Something like this?

get-childitem -recurse -filter *.exe | 
      %{Write-Host Examining file: $_.fullname; $_} | 
      measure-object -Property length -Average
挖鼻大婶 2024-11-11 15:45:11

更详细一点的进展:

$images = get-childitem  -recurse -filter *.jpeg

$images | % -begin { $i=0 } `
-process {  write-progress -activity "Computing average..." -status "Examining File: $image.fullpath ($i of $($images.count))" -percentcomplete ($i/$images.count*100); $i+=1 } `
-end { write-output "Average file size is: $($images | measure-object -Property length -Average)" }

A little more detailed progress:

$images = get-childitem  -recurse -filter *.jpeg

$images | % -begin { $i=0 } `
-process {  write-progress -activity "Computing average..." -status "Examining File: $image.fullpath ($i of $($images.count))" -percentcomplete ($i/$images.count*100); $i+=1 } `
-end { write-output "Average file size is: $($images | measure-object -Property length -Average)" }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文