gpt4 book ai didi

powershell - 我可以根据其值获得子属性吗?

转载 作者:行者123 更新时间:2023-12-03 00:06:55 24 4
gpt4 key购买 nike

我正在尝试整理音乐。因此,我想删除不必要的标签,而只使用“贡献者”标签,而不是“贡献者”和“创作者”的混合体

我为此使用Taglib-Sharp

因此,在此之后:

Add-Type -Path "$PWD\taglib-sharp.dll"
cd "$Home\Music"
$songs = ((Get-ChildItem *.mp3 -Recurse).Fullname)
$taglib = ($songs | % {[TagLib.File]::Create($_)})

我在 $taglib中加载了音乐库。现在,我想搜索所有子属性,其中包括“link.com”之类的东西。例如: $taglib具有属性“length”,“name”, “tag” [...]。
本身具有“艺术家”,“相册”,“名称”属性。

所以我想遍历 $taglib中每个元素/歌曲的所有子属性,并根据其值找到一个属性。我试图制作一个函数,该函数接受一个对象,并在对象具有属性的情况下递归调用自身:
function AllProps($obj){ 
foreach($member in (gm -inputobject $obj -membertype property).name){
if($member -eq $null) {
$obj
} else {
"$member"
AllProps -obj $obj.$member
}
}
}

但是它陷入了循环...
有没有简单的出路? TIA!

最佳答案

尝试这样的事情:

filter ExpandProperty {
$obj = $_
$obj | get-member -MemberType *property | foreach {
#Find objects with array value
if( @($obj.($_.Name)).Count -gt 1 ) {
$count = 1
$prop = $_.Name
$obj.($prop) | foreach {
#Foreach value in the property
$obj | Add-Member NoteProperty -Name "$prop (Property $($count))" -Value $_
$count++
}
}
}
#Output object
$obj
}

$taglib | ExpandProperty

关于powershell - 我可以根据其值获得子属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59365871/

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