本文介绍了在powershell中按比特率递归获取文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 powershell 列出文件(音频)比特率大于 32kbps 的目录中的所有文件(递归)?
How can you list all files (recursively) within a directory where the file (audio) bit rate is greater than 32kbps using powershell?
推荐答案
从 link (新链接位置)来自 Johannes 的帖子,这是一个使用 GetDetailsOf
以最小比特率查找目录中的所有 mp3 文件:
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 }
}
}
这篇关于在powershell中按比特率递归获取文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!