使用Powershell获取文件元数据

3

我希望获取指定文件(或文件目录)的元数据,这与IT技术有关。我特别寻找.WTV文件上的“程序描述”。

我找到了一些代码,但它没有列出该属性。其中一些代码如下:

 foreach($sFolder in $folder) 
  { 
   $a = 0 
   $objShell = New-Object -ComObject Shell.Application 
   $objFolder = $objShell.namespace($sFolder) 

   foreach ($strFileName in $objFolder.items()) 
    { FunLine( "$($strFileName.name)") 
      for ($a ; $a  -le 266; $a++) 
       {  
         if($objFolder.getDetailsOf($strFileName, $a)) 
           { 
             $hash += @{ ` 
                   $($objFolder.getDetailsOf($objFolder.items, $a))  =` 
                   $($objFolder.getDetailsOf($strFileName, $a))  
                   } #end hash 
            $hash 
            $hash.clear() 

在文件资源管理器中,我可以看到该属性。

4个回答

2

你提供的代码 @user1921849 已经接近正确,但为了更清晰地回答原问题,您应该使用Windows Shell属性系统中命名为属性的属性,在WTV文件的Windows开发人员文档中列出,并在下面的第4行中使用。

$shell = new-object -com shell.application
$folder = $shell.namespace("\\MEDIA\Recorded Tv\")
$item = $folder.Items().Item('Person of Interest_WBBMDT_2013_11_26_21_01_00.wtv')
write-output $item.ExtendedProperty('System.RecordedTV.ProgramDescription')

更新了文档的URL

  1. 常规属性列表https://learn.microsoft.com/en-us/windows/desktop/properties/props
  2. WTV属性列表https://learn.microsoft.com/en-us/windows/desktop/properties/recordedtv-bumper

1
这个方法完美地从字体文件中提取了标题,非常感谢!(使用了 System.Title) - chazbot7

0
$shell = new-object -comobject shell.application
$ShFolder=$shell.namespace("\\MEDIA\Recorded Tv\")
$ShFile    =$ShFolder.parsename("Person of Interest_WBBMDT_2013_11_26_21_01_00.wtv")

$count = 0

while ($count -le 294)
    {
    $ShRating  = $ShFolder.getdetailsof($ShFile,$count)

    $count
    $ShRating
    $count = $count+1
    }

程序描述是第272项。


0

我使用了TagLib。这是用于带有ID3v1和ID3v2标签的音频文件的工具。 - user1612851
嗯,taglib-sharp声称它是一个用于读写包括视频、音频和照片格式在内的媒体文件元数据的库。 - Keith Hill
好的...这与TagLib不同。我会看一下。 - user1612851
看起来它可以处理像mpeg、avi这样的格式,但不能处理WTV格式。 - user1612851

0

我已经编写了一个示例代码,用于检查文件夹中的所有文件并导出包含所有元数据细节的 csv 文件。请查看以下 PowerShell 脚本。

步骤1. 创建一个名为 Fileproperty.ps1 的文件

Import-Module ".\Module\AddModule.psm1" -Force
$commands = {
  $source = read-host "Enter folder path "  

if ([string]::IsNullOrWhitespace($source)){
    Write-host "Invalid file path, re-enter."
    $source = $null 
     &$commands
}else{
    $output = read-host "Enter output folder path "
     if ([string]::IsNullOrWhitespace($output)){
        Write-host "Invalid output path, re-enter."
        $output = $null
         &$commands
    }else{
        $outputfilename = read-host "Enter output file name "
        if ([string]::IsNullOrWhitespace($outputfilename)){
            Write-host "Invalid file name, re-enter."
            $outputfilename = $null
             &$commands
        }else{
            Get-FileMetaData -folder $source | Export-Csv -Path $output\$outputfilename.csv -Encoding ascii -NoTypeInformation   
            Write-host "Process has been done..."
        }   

    }

  }
}
&$commands 

步骤2. 创建一个名为Module的文件夹

步骤3. 创建另一个文件Module/AddModule.psm1

$FunctionFiles = @(Get-ChildItem -Path $PSScriptRoot\*.ps1 -ErrorAction SilentlyContinue)
Foreach($fileItem in @($FunctionFiles))
{
    Try
    {
        . $fileItem.fullname
    }
    Catch
    {
        Write-Error -Message "Vsts module -> Unable to import a function in file $($fileItem.fullname): $_"
    }
}
Export-ModuleMember -Function $FunctionFiles.Basename

步骤4. 创建另一个文件 Module/Get-FileMetaData.ps1

Function Get-FileMetaData
{ 
 Param([string[]]$folder) 
 $OutputList = New-Object 'System.Collections.generic.List[psobject]'
 foreach($sFolder in $folder) {
   $a = 0 
   $objShell = New-Object -ComObject Shell.Application 
   $objFolder = $objShell.namespace($sFolder)  
   foreach ($File in $objFolder.items()) 
    {  
      $FileMetaData = New-Object PSOBJECT 
      for ($a ; $a  -le 266; $a++) 
      {  
     if($objFolder.getDetailsOf($File, $a)) 
       { 
         $hash += @{$($objFolder.getDetailsOf($objFolder.items, $a))  = 
               $($objFolder.getDetailsOf($File, $a)) } 
        $FileMetaData | Add-Member $hash 
        $hash.clear()  
       } #end if 
   } #end for  
 $a=0 

    $OutputList.Add($FileMetaData)
   } #end foreach $file   
  } #end foreach $sfolder 
  return $OutputList
} #end Get-FileMetaData

希望这对你有用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接