当前位置 博文首页 > Powershell获取图片名字、文件夹及拍摄时间的例子

    Powershell获取图片名字、文件夹及拍摄时间的例子

    作者:admin 时间:2021-02-07 18:22

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

    这个例子使用一个系统函数获得”我的图片”的路径,接着从其目录和子目录查询所有的文件。获得的结果通过管道符传递给函数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

    js
    下一篇:没有了