gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 00:52:25 24 4
gpt4 key购买 nike

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

最佳答案

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

关于powershell - 在Powershell中按比特率递归获取文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1153819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com