다른 카메라로 찍은 사진이 들어 있는 폴더가 있는데 이 모든 사진에는 올바른 내용이 있습니다.날짜시간원본EXIF 태그가 설정되었습니다.
다음과 같은 파일 목록을 가정해 보겠습니다.
20150831_153712.jpg
IMG_5246.JPG
IMG_5247.JPG
20150902_201425.jpg
이제 이러한 방식으로 해당 파일의 이름을 바꾸는 방법을 알고 싶습니다.날짜시간원본물론 태그:
001_IMG_5246.JPG
002_20150831_153712.jpg
003_IMG_5247.JPG
004_20150902_201425.jpg
기본적으로 나는 원한다엑시프툴(또는 직접적으로 가능하지 않은 경우 Windows 배치 프로그램)종류JPEG의 전체 폴더날짜시간원본오름차순이며 이름 바꾸기 작업은카운터파일 이름 앞에 접두사를 추가합니다(따라서 원래 파일 이름 유지).
나는 또한 다음을 수행하는 방법을 원합니다.이름 바꾸기를 미리 보는 테스트 명령문제가 발생하기 전에(뭔가 잘못되었는지 확인하기 위해테스트 이름꼬리표).
답변1
ExifTool과 함께 사용하려는 항목은 -FileOrder
옵션과 FileSequence
태그, 그리고 고급 포맷 옵션을 사용하는 약간의 Perl입니다. FileOrder 옵션은 옵션으로 나열한 시간을 기준으로 파일을 정렬합니다. 이렇게 하면 각 파일을 두 번 읽어야 하기 때문에 ExifTool 속도가 약간 느려지지만 일반적으로 루프마다 ExifTool을 호출하고 반복하는 것과 같은 다른 옵션보다 빠릅니다. FileSequence 태그는 ExifTool 내부에 있으며 현재 처리 중인 파일 수를 추적합니다. 0부터 시작하므로 고급 처리에서 1을 추가해야 합니다. 또한 0을 채워 최소 3자가 되도록 하겠습니다.
다음 명령을 시도해 보세요.
ExifTool "-TestName<${FileSequence;$_=0 x(3-length($_+1)).($_+1)}_$filename" -FileOrder DateTimeOriginal DIR
작동하는 경우 다음 -TestName
으로 바꾸십시오 -FileName
.
ExifTool "-FileName<${FileSequence;$_=0 x(3-length($_+1)).($_+1)}_$filename" -FileOrder DateTimeOriginal DIR
패딩된 0의 개수를 변경하려면 3을 3-length
원하는 숫자로 변경하세요. 시작 번호를 변경하려면 의 1을 변경하세요 $_+1
.
답변2
몇 가지 이름 바꾸기 도구를 확인했습니다. 가장 큰 문제는 다음과 같은 도구입니다.마스터 이름 바꾸기그리고ExifToolEXIF 데이터에 액세스할 수 있습니다. 하지만 번호가 매겨진 목록을 생성하는 방법을 찾을 수 없습니다.
그래서 이를 위해 PowerShell 스크립트를 작성했습니다. 나는 각 줄에 주석을 달았습니다. 이해하기 쉬워야 합니다. 그냥 읽어보세요.
가장 먼저 한 일은 검색이었습니다."DateTimeOriginal"의 ID그래서 우리는 사용할 수 있습니다 GetPropertyItem(MyExifID)
. 둘째, 실제로 DateTimeOriginal이 있는 특정 폴더의 모든 이미지를 배열에 추가합니다. 여기서부터는 쉬웠습니다. 날짜 열을 기준으로 배열을 정렬하고 간단한 카운터를 증가시킨 다음 패턴으로 새 파일 이름을 만듭니다 000_oldname
.
이 스크립트는 아무것도 수정하지 않습니다.다음과 같은 내용만 출력됩니다.
이를 사용하여 스크립트가 수행할 작업을 확인합니다. 가능한 결과를 확인한 후 #
행 앞의 주석 표시를 제거하십시오 #Rename-Item $_[0].Fullname $newName
.이제부터 스크립트는 이에 따라 파일 이름을 바꿉니다.
RenameFromExif.ps1
# Set image folder to process
$strDirectory = "T:\Pictures"
# Create empty array
$arrSortMe = @()
# Load Windows library to access EXIF data
[void][Reflection.Assembly]::LoadWithPartialName("System.Drawing")
# Loop through all JPGs and JPEGs in the given image folder
Get-ChildItem -Path "$strDirectory\*" -Include *.jpg,*.jpeg | ForEach {
# Load current image into Powershell as bitmap object
$img = New-Object -TypeName system.drawing.bitmap -ArgumentList $_.FullName
# Error handling for images which doesn't have the specified EXIF data
Try {
# Get EXIF data with ID 36867 - which is "DateTimeOriginal"
$intExif = [Byte[]]$img.GetPropertyItem(36867).Value
# Release image or else later we can't rename it
$img.Dispose()
# Convert EXIF data from byte array to string
$strExif = [System.Text.Encoding]::Default.GetString($intExif, 0, $intExif.Length-1)
# Convert EXIF data from string to datetime
$dateExif = [DateTime]::ParseExact($strExif, 'yyyy:MM:dd HH:mm:ss', $null)
# Add to multidimensional array: [0]=current_file and [1]=datetime
$arrSortMe += ,@($_, $dateExif)
}
Catch {}
}
Write-host "DateTimeTaken" `t`t`t "New Name" `t`t`t "Old Fullname"
# Sort array by datetime and pipe the sorted array to a foreach loop
$arrSortMe | Sort-Object @{Expression={$_[1]} } | ForEach {$i=0}{
# Increment a simple counter starting with 0, so the first image gets the "1"
$i++
# Format the counter to 3-digits, append an underscore followed by the old image name
$newName = $i.ToString("000") + "_" + $_[0].Name
# Don't rename images which already have three digits as filename start
If ($_.Name -notmatch "^[\d]{3}_") {
#Rename-Item $_[0].Fullname $newName
}
# Only for debugging
Write-host $_[1].Date `t $newName `t $_[0].Fullname
}
# Clear all variables. System variables are readonly so we don't mind using * to get all
Remove-Variable * -ErrorAction SilentlyContinue
사용된 자원
- http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif.html
- http://blogs.technet.com/b/jamesone/archive/2007/07/13/exploring-photographic-exif-data-using-powershell-of-course.aspx
- http://blog.cincura.net/233463-renaming-files-based-on-exif-data-in-powershell/
- http://www.happysysadm.com/2011/01/multiDimensional-arrays-in-powershell.html
- http://www.orcsweb.com/blog/james/fun-with-powershell-sorting-multiDimensional-arrays-and-arraylists/
- http://blogs.technet.com/b/heyscriptingguy/archive/2008/06/02/hey-scripting-guy-how-can-i-use-leading-zeroes-when-displaying-a-value-in- windows-powershell.aspx