将EXIF DateTaken设置为文件CreationTime [英] Set EXIF DateTaken as file CreationTime

查看:70
本文介绍了将EXIF DateTaken设置为文件CreationTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Powershell修复照片的元数据. 我需要将exif DateTaken设置为文件CreationTime

I'm trying to fix metadata of my photos using powershell. I need to set exif DateTaken as file CreationTime

这是我的代码:

[reflection.assembly]::loadfile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll")
echo "--------"
echo ""
$files = Get-ChildItem E:\Photos\*.*
ForEach ($file in $files) {

        #Get Date
    $foo=New-Object -TypeName system.drawing.bitmap -ArgumentList $file.fullname 
    $date = $foo.GetPropertyItem(36867).value[0..9]
    $arYear = [Char]$date[0],[Char]$date[1],[Char]$date[2],[Char]$date[3]  
    $arMonth = [Char]$date[5],[Char]$date[6]  
    $arDay = [Char]$date[8],[Char]$date[9]  
    $strYear = [String]::Join('',$arYear)  
    $strMonth = [String]::Join('',$arMonth)   
    $strDay = [String]::Join('',$arDay)  
    $DateTaken = $strDay + "/" + $strMonth + "/" + $strYear


        # Get Time
    $time = $foo.GetPropertyItem(36867).value[11..18]
    $arHour = [Char]$time[0],[Char]$time[1]
    $arMinute = [Char]$time[3],[Char]$time[4]  
    $arSecond = [Char]$time[6],[Char]$time[7]  
    $strHour = [String]::Join('',$arHour)  
    $strMinute = [String]::Join('',$arMinute)   
    $strSecond = [String]::Join('',$arSecond)  
    $TimeTaken = $strHour + ":" + $strMinute + ":" + $strSecond

        # Link into one date and time
    $FullDate = $DateTaken + " " + $TimeTaken

    echo "File name"
    echo $file.name
    echo ""
    echo "Wrong data"
    echo (Get-Item $file).creationtime.datetime
    echo ""
    echo "Right data"
    echo $FullDate
    echo ""

        #Set DateTaken as CreationTime 
    (Get-Item $file).creationtime= $FullDate

    pause
}

我收到错误消息由于另一个进程正在使用该文件而无法访问该文件". 我不知道如何解决它.

I got error "cannot access the file because it is being used by another process". I have no idea how to fix it.

PS.我不确定$FullDate是否具有正确的语法,因为我无法对其进行测试

PS. I'm not sure if $FullDate has right syntax, because I couldn't test it

谢谢

推荐答案

您是否尝试过通过调用$ foo.dispose()摆脱$ foo对象?

Have you tried get rid of the $foo object by calling $foo.dispose()?

这篇关于将EXIF DateTaken设置为文件CreationTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆