首页 > 解决方案 > 使用 Powershell 函数(从 MATLAB 调用)编辑文件元数据

问题描述

我正在尝试使用 Powershell 以编程方式访问本地文件元数据(类似于 .mp3 文件中的“作者”或“专辑”等字段)(主要原因是在我看来,这似乎是从 MATLAB 实现这一目标的最可行方法)。

到目前为止,我已经设法读取了元数据。我想出了以下功能:

param(        
    [string]$folderName = "C:\temp\Powershell\test",
    [string]$fileName = "test.txt",
    [string]$attrNameToSearch = "Size"
    )


$objShell = New-Object -ComObject Shell.Application  
$objFolder = $objShell.namespace($folderName) 

$iAttr = 0     
while($objFolder.getDetailsOf($objFolder.items, $iAttr) -ne $attrNameToSearch) {
    $iAttr += 1    
}

$file = $objFolder.ParseName($fileName)

$attrValue = $objFolder.getDetailsOf($file, $iAttr)             

return $attrValue 

它似乎在 ISE 以及当我从 MATLAB 调用它时都可以完美运行:

cmd = sprintf(['powershell -file psFunction4.ps1 -folderName c:\\temp\\Powershell\\test -fileName ', fileNames{iF}, ' -attrName Size']);
[~, b] = system(cmd)

现在的问题是:有没有办法使用类似的方法来编辑元数据?

提前致谢。

标签: matlabpowershellattributesmetadata

解决方案


推荐阅读