How can I get programmatic access to the “Date taken” field of an image or video using powershell?

前端 未结 2 1392
清酒与你
清酒与你 2021-02-13 03:37

I\'m trying convert a bunch of pictures and videos, but when I convert it to a new format I obviously lose the properties of the original file. I\'d like to be able to read the

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-13 04:34

    In general, you can access any extended property for a file shown in explorer through the shell GetDetailsOf method. Here's a short example, adapted from another answer:

    $file = Get-Item IMG_0386.jpg
    $shellObject = New-Object -ComObject Shell.Application
    $directoryObject = $shellObject.NameSpace( $file.Directory.FullName )
    $fileObject = $directoryObject.ParseName( $file.Name )
    
    $property = 'Date taken'
    for(
      $index = 5;
      $directoryObject.GetDetailsOf( $directoryObject.Items, $index ) -ne $property;
      ++$index ) { }
    
    $value = $directoryObject.GetDetailsOf( $fileObject, $index )
    


    However, according to the comments on another question, there is no general-purpose mechanism for setting these properties. The System.Drawing.Bitmap class that EBGreen mentioned will work for images, but I'm afraid I also do not know of a .NET option for video files.

提交回复
热议问题