Powershell获取图片的拍摄时间 2


如果你想要整理你的图片档案,这里有一段代码它能从图片文件获取相关的拍摄信息。

这个例子使用一个系统函数获得”我的图片”的路径,接着从其目录和子目录查询所有的文件。获得的结果通过管道符传递给函数Get-DateTaken,它将返回这些图片的名字、文件夹及照片的拍摄日期。

function Get-DateTaken
{
  param 
  (
    [Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
    [Alias('FullName')]
    [String]
    $Path
  )
  
  begin
  {
    $shell = New-Object -COMObject Shell.Application
  }
  
  process
  {
  $returnvalue = 1 | Select-Object -Property Name, DateTaken, Folder
    $returnvalue.Name = Split-Path $path -Leaf
    $returnvalue.Folder = Split-Path $path
    $shellfolder = $shell.Namespace($returnvalue.Folder)
    $shellfile = $shellfolder.ParseName($returnvalue.Name)
    $returnvalue.DateTaken = $shellfolder.GetDetailsOf($shellfile, 12)

    $returnvalue
  }
}


$picturePath = [System.Environment]::GetFolderPath('MyPictures')
Get-ChildItem -Path $picturePath -Recurse -ErrorAction SilentlyContinue | 
  Get-DateTaken

原文地址:Getting DateTaken Info from Pictures

心得:

学习下这种管道直接传给自创函数的方法。

本文链接: https://www.pstips.net/getting-datetaken-info-from-pictures.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

回复 小楼 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

2 条评论 “Powershell获取图片的拍摄时间