【问题标题】:Get list of files recursively by bit rate in powershell在powershell中按比特率递归获取文件列表
【发布时间】:2009-07-20 14:10:53
【问题描述】:

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

【问题讨论】:

    标签: powershell bitrate


    【解决方案1】:

    Johannes' post 中的link (new link location) 开始,这里有一个简单的函数,它使用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 }
      }
    }
    

    【讨论】:

    • 这回答了这个问题(并且有效)。恕我直言,这应该是公认的答案。
    【解决方案2】:

    嗯,第一部分肯定是Get-ChildItem -Recurse。但是,对于比特率,您需要更多的脚本。 Microsoft Scripting Guys 不久前回答了一个问题:How Can I find Files' Metadata。您可能可以使用它来获取音频比特率并对其进行过滤。

    【讨论】:

    • @ggorlen:链接已修复。
    【解决方案3】:

    一般来说,如果你想做一些你知道内置 Windows 组件原生支持的事情,最快的途径可能是 COM。 James Brundage has a great post 动态发现这些功能并迅速投入使用。

    【讨论】:

      【解决方案4】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-10-07
        • 2013-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多