Powershell获取文件的元数据

时间:2014-01-29 02:33:00

标签: powershell metadata

我希望获取指定文件(或文件目录)的元数据。我特意在.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() 

我可以在File explorer中看到该属性。

4 个答案:

答案 0 :(得分:2)

您拥有的代码@ user1921849几乎已经得到了它,但为了更清楚地解决原始问题,您应该使用Windows devloper documentation for WTV files中列出的Windows Shell Property System命名属性,并在下面的第4行中使用。< / p>

$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')

更新了文档的网址

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

答案 1 :(得分:0)

抓住TagLib# from Nuget或其他各种地方。然后查看此blog post showing how to use TagLib# to edit MP3 tags。希望它可以检索您正在寻找的WTV标签。

答案 2 :(得分: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项。

答案 3 :(得分: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步。创建一个文件夹模块

步骤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

希望这对您有用。