- ExifTool
- libwebp 1.4.0 (optional)
C:.
│ exiftool.exe
│
├─1-1_movie_escaping
│ exiftool.exe
│
├─1-2_create_date_setting
│ exiftool.exe
│
└─5_original_files
cd C:\Users\%username%\Downloads
mkdir picture_backup & mkdir picture_backup\1-2_create_date_setting & mkdir picture_backup\5_original_files
cd picture_backup
- ①は、「
C:\Users\${username}\Downloads\picture_backup
」に入れる。
- ②は、「
C:\Users\${username}\Downloads\picture_backup\1-2_create_date_setting
」に入れる。
start powershell
- mp4ファイルなどを退避させる。(③になる)
Move-Item -Path *.mp4 -Destination .\1-1_movie_escaping
- ②に対してSetting createDate with my FileCreateDate.
cd 1-2_create_date_setting; $username = (Get-ChildItem Env:\USERNAME).Value; $toCreateDateDir = "1-2_create_date_setting"; $folderDir = "C:\Users\${username}\Downloads\picture_backup\${toCreateDateDir}"; $proc = Start-Process -FilePath "${folderDir}\exiftool" -ArgumentList "-CreateDate<FileCreateDate","-d","%Y:%m:%d:%H:%M:%S",$folderDir -NoNewWindow -PassThru -wait; Write-Host $proc.ExitCode;
- ③に対してSetting createDate with my FileModifyDate.
cd ..; cd 1-1_movie_escaping; $username = (Get-ChildItem Env:\USERNAME).Value; $toCreateDateDir = "1-1_movie_escaping"; $folderDir = "C:\Users\${username}\Downloads\picture_backup\${toCreateDateDir}"; $proc = Start-Process -FilePath "${folderDir}\exiftool" -ArgumentList "-CreateDate<FileModifyDate","-d","%Y:%m:%d:%H:%M:%S",$folderDir -NoNewWindow -PassThru -wait; Write-Host $proc.ExitCode;
Move-Item -Path .\*.mp4 -Destination ..;
cd ..
$username = (Get-ChildItem Env:\USERNAME).Value; $folderDir = "C:\Users\${username}\Downloads\picture_backup"; $proc = Start-Process -FilePath "${folderDir}\exiftool" -ArgumentList "-FileName<CreateDate","-d","%Y%m%d%H%M%S.%%e",$folderDir -NoNewWindow -PassThru -wait; Write-Host $proc.ExitCode;
cd .\1-2_create_date_setting
Move-Item -Path *.jpg -Destination ..;
Move-Item -Path *.webp -Destination ..;
cd ..
$number = 1
$date_formatted = Get-Date -Format "yyyyMMddHH"
$year_this = Get-Date -UFormat "%Y"
$year_last = Get-Date (Get-Date).AddYears(-1) -UFormat "%Y"
$is_correct = $false
function getUnitOfDatetime([string]$numStr){
$num = [int]$numStr;
return [string]$num
}
function getZeroPaddedUnit4([string]$numStr){
return [string]"{0:0000}" -f [int]$numStr
}
function getZeroPaddedUnit2([string]$numStr){
return [string]"{0:00}" -f [int]$numStr
}
while($is_correct -eq $false){
$date_formatted = Read-Host "Input prefix of pictures (yyyyMMddHH)"
if($date_formatted.length -eq 10 -and $date_formatted -like "${year_this}*" -or $date_formatted -like "${year_last}*"){
$is_correct = $true
}
$y = getZeroPaddedUnit4(getUnitOfDatetime($date_formatted.Substring(0, 4)));
$m = getZeroPaddedUnit2(getUnitOfDatetime($date_formatted.Substring(4, 2)));
$d = getZeroPaddedUnit2(getUnitOfDatetime($date_formatted.Substring(6, 2)));
$h = getZeroPaddedUnit2(getUnitOfDatetime($date_formatted.Substring(8, 2)));
$newCreateDate = "{0}-{1}-{2} {3}:00:00" -f $y, $m, $d, $h;
Write-Host $newCreateDate;
}
Get-ChildItem -Path . -File | ForEach-Object {
if($_ -notlike "${year_this}*" -and $_ -notlike "${year_last}*" -and $_ -notlike "*.exe" -and $_ -isnot [System.IO.DirectoryInfo]){
Write-Host "LOG-INFO" $_.GetType() "true" $_.Name
$jpgFilePath = $_.FullName;
./exiftool.exe -AllDates="$newCreateDate" "$jpgFilePath"
$number_zeropadded = "{0:0000}" -f $number
$ext = [System.IO.Path]::GetExtension($_)
$newName = "${date_formatted}${number_zeropadded}${ext}"
Write-Host "LOG-INFO" $newName
Rename-Item -Path ".\${_}" -NewName $newName
$number++
}else{
Write-Host "LOG-INFO" $_.GetType() "false" $_.Name
}
}
Write-Output("Exif info of {0} images are fixed with prompted dates." -f [string]($number-1));
作業を続ける。
Cwebpでwebpにする場合の手順
まずは、Scoop
をインストールして、libwebp
をインストールする。
cd ..\..\..\..\ # Change to "C:\" directory.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
cd C:\Users\%USERNAME%\Downloads\picture_backup
scoop update
scoop install libwebp
そして、全部Webpにする。(Jpegはまだ消さない。)
$TargetFolder = "."; if ($null -ne $Args[0]) {$TargetFolder = $Args[0];}; $Files = (Get-ChildItem $TargetFolder -Name -File -Include "*.jpg","*.png"); $updatedCount = 0; foreach ($File in $Files) {$FullName = "$TargetFolder/$File"; $Extension = (Get-Item $FullName).Extension; $GenerateFileName = "$($FullName.Substring(0,$FullName.Length-$Extension.Length)).webp"; Write-Output "<Source File Name: $File>"; cwebp -preset photo -metadata icc -sharp_yuv -q 75 -o $GenerateFileName -progress -short $FullName; $updatedCount++; Write-Output "----------------"; }; Write-Output("{0} .webp images converted." -f $updatedCount);
- 全部「
C:\Users\${username}\Downloads\picture_backup
」に入れる。
- 全部、Copying Exif info from other file.
$updatedCount = 0; Get-ChildItem *.webp | ForEach-Object {$jpg = $_.FullName.Replace(".webp", ".jpg"); if(Test-Path $jpg){ $webpFilePath = $_.FullName; Write-Host $jpg; Write-Host $webpFilePath; Start-Process -FilePath "./exiftool.exe" -ArgumentList "-tagsFromFile",$jpg,"-exif:all",$webpFilePath -NoNewWindow -Wait; $updatedCount++; }}; Write-Output("Exif info of {0} .webp images are fixed with .jpg images." -f $updatedCount);
- コピー元のoriginalファイルを「
C:\Users\${username}\Downloads\picture_backup\original_files
」移動する。
Move-Item -Path .\*_original -Destination .\5_original_files;
Move-Item -Path .\*.jpg -Destination .\5_original_files;
Move-Item -Path .\*.png -Destination .\5_original_files;
- 全部、Googleフォトにアップロードして終わり。アルバムに振り分ける。
exiftool -s .\img.webp
Execute the batch file: Z1-1_rename_vlcsnap_files.bat.
Date | Topics |
---|---|
2024-02-20 | Initial commit. |
2024-06-14 | Apply Cwebp to convert to .webp files. |
2024-06-16 | Fix bugs and Edit exif with prompted date. |
2024-06-19 | Apply the function to rename the files captured with VLC media player. |