在powershell中按比特率递归获取文件列表

发布于 2024-07-27 12:52:05 字数 58 浏览 9 评论 0原文

如何使用 powershell 列出文件(音频)比特率大于 32kbps 的目录中的所有文件(递归)?

How can you list all files (recursively) within a directory where the file (audio) bit rate is greater than 32kbps using powershell?

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

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

发布评论

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

评论(4

枕梦 2024-08-03 12:52:05

链接开始新链接位置)来自 Johannes ' 帖子,这是一个简单的函数,使用 GetDetailsOf 查找目录中具有最低比特率的所有 mp3 文件:

function Get-Mp3Files( [string]$directory = "$pwd", [int]$minimumBitrate = 32 ) {
  $shellObject = New-Object -ComObject Shell.Application
  $bitrateAttribute = 0

  # Find all mp3 files under the given directory
  $mp3Files = Get-ChildItem $directory -recurse -filter '*.mp3'
  foreach( $file in $mp3Files ) {
    # Get a shell object to retrieve file metadata.
    $directoryObject = $shellObject.NameSpace( $file.Directory.FullName )
    $fileObject = $directoryObject.ParseName( $file.Name )

    # Find the index of the bit rate attribute, if necessary.
    for( $index = 5; -not $bitrateAttribute; ++$index ) {
      $name = $directoryObject.GetDetailsOf( $directoryObject.Items, $index )
      if( $name -eq 'Bit rate' ) { $bitrateAttribute = $index }
    }

    # Get the bit rate of the file.
    $bitrateString = $directoryObject.GetDetailsOf( $fileObject, $bitrateAttribute )
    if( $bitrateString -match '\d+' ) { [int]$bitrate = $matches[0] }
    else { $bitrate = -1 }

    # If the file has the desired bit rate, include it in the results.
    if( $bitrate -ge $minimumBitrate ) { $file }
  }
}

Starting with the link (new link location) from Johannes' post, here is a simple function that uses GetDetailsOf to find all mp3 files in a directory with a minimum bitrate:

function Get-Mp3Files( [string]$directory = "$pwd", [int]$minimumBitrate = 32 ) {
  $shellObject = New-Object -ComObject Shell.Application
  $bitrateAttribute = 0

  # Find all mp3 files under the given directory
  $mp3Files = Get-ChildItem $directory -recurse -filter '*.mp3'
  foreach( $file in $mp3Files ) {
    # Get a shell object to retrieve file metadata.
    $directoryObject = $shellObject.NameSpace( $file.Directory.FullName )
    $fileObject = $directoryObject.ParseName( $file.Name )

    # Find the index of the bit rate attribute, if necessary.
    for( $index = 5; -not $bitrateAttribute; ++$index ) {
      $name = $directoryObject.GetDetailsOf( $directoryObject.Items, $index )
      if( $name -eq 'Bit rate' ) { $bitrateAttribute = $index }
    }

    # Get the bit rate of the file.
    $bitrateString = $directoryObject.GetDetailsOf( $fileObject, $bitrateAttribute )
    if( $bitrateString -match '\d+' ) { [int]$bitrate = $matches[0] }
    else { $bitrate = -1 }

    # If the file has the desired bit rate, include it in the results.
    if( $bitrate -ge $minimumBitrate ) { $file }
  }
}
花想c 2024-08-03 12:52:05

嗯,第一部分肯定是 Get-ChildItem -Recurse。 然而,对于比特率,您需要更多的脚本。 Microsoft 脚本专家不久前回答了一个问题:如何查找文件的元数据。 您可能可以使用它来获取音频比特率并对其进行过滤。

Well, the first part would definitely be a Get-ChildItem -Recurse. For the bit rate, you would need some more scripting, however. The Microsoft Scripting Guys answered a question to that a while ago: How Can I find Files' Metadata. You can probably use that to get to the audio bit rate and filter for that.

林空鹿饮溪 2024-08-03 12:52:05

一般来说,如果您想做一些您知道内置 Windows 组件本机支持的事情,最快的途径可能是 COM。 James Brundage 有一篇关于发现的精彩文章这些功能是动态的和动态的 快速使用它们。

In general, if you want to do something you know is natively supported by a built-in Windows component, the fastest route is likely to be COM. James Brundage has a great post on discovering these capabilities on the fly & quickly putting them to use.

眼中杀气 2024-08-03 12:52:05

了不起的皇帝! 我意识到我有一些 56K MP3,我应该更换为更高质量的(嘿,当驱动器以数百兆而不是演出来测量时,它们被撕裂了,节省空间才是最重要的!)今天早上我想我可能应该看到如果有办法在 Powershell 下做到这一点(我曾经有一个名为 EDIR 的程序,可以从文件中获取该信息,但那是在 Win 95 时代......),并且此页面是 powershell 下的第一个点击OR monad mp3 比特率提取。 谈论幸运!

我还可以想办法改变这一点,这样我就可以浏览并选择所有 16:9、16:10 或左右的壁纸,如果没有别的办法,只是为了对它们进行分类。 16:9-10、4:3(纵向)、9-10:16、3:4(横向)、方形等。 对我来说,这听起来像是我(哈!)业余时间的一个计划。

Stupendous Emperor! I realized that I had some 56K MP3s that I should replace with better quality (heh, they were ripped when drives were measured by hundreds of megs, not gigs, saving space was what mattered!) And I thought this morning that I should probably see if there's a way to do that under Powershell (I used to have a program called EDIR that would get that info from files, but that was back in the days of Win 95...), and this page was the first hit under powershell OR monad mp3 bitrate extraction. Talk about getting lucky!

I could also figure out to change this so I can go through and pick all the wallpapers that are 16:9, 16:10 or thereabouts, if nothing else just to categorize them. 16:9-10, 4:3 (portrait), 9-10:16, 3:4 (landscape), square, and other. Sounds like a plan to me in my (ha!) spare time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文