mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-06-20 03:37:56 +02:00
Updated copy-photos-sorted.ps1
This commit is contained in:
parent
9befcc9000
commit
7d16c37f1f
@ -10,7 +10,8 @@
|
|||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./copy-photos-sorted.ps1 D:\iPhone\DCIM C:\MyPhotos
|
PS> ./copy-photos-sorted.ps1 D:\iPhone\DCIM C:\MyPhotos
|
||||||
⏳ Copying IMG_20240903_134445.jpg to C:\MyPhotos\2024\09 SEP\...
|
⏳ Copying IMG_20240903_134445.jpg to C:\MyPhotos\2024\09 SEP\...
|
||||||
✅ Copied 1 photo to 📂C:\MyPhotos in 13s (0 skipped).
|
...
|
||||||
|
✅ 123 photos copied to 📂C:\MyPhotos in 13s (0 skipped).
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -19,7 +20,7 @@
|
|||||||
|
|
||||||
param([string]$sourceDir = "", [string]$targetDir = "")
|
param([string]$sourceDir = "", [string]$targetDir = "")
|
||||||
|
|
||||||
function CopyFile { param([string]$sourcePath, [string]$targetDir, [int]$date, [string]$filename)
|
function CopyPhoto([string]$sourcePath, [string]$targetDir, [int]$date, [string]$filename) {
|
||||||
[int]$year = $date / 10000
|
[int]$year = $date / 10000
|
||||||
[int]$month = ($date / 100) % 100
|
[int]$month = ($date / 100) % 100
|
||||||
$monthDir = switch($month) {
|
$monthDir = switch($month) {
|
||||||
@ -65,22 +66,22 @@ try {
|
|||||||
$filename = (Get-Item "$file").Name
|
$filename = (Get-Item "$file").Name
|
||||||
if ("$filename" -like "IMG_*_*.jpg") {
|
if ("$filename" -like "IMG_*_*.jpg") {
|
||||||
$array = $filename.split("_")
|
$array = $filename.split("_")
|
||||||
$skipped += CopyFile "$file" "$targetDir" $array[1] "$filename"
|
$skipped += CopyPhoto "$file" "$targetDir" $array[1] "$filename"
|
||||||
} elseif ("$filename" -like "IMG-*-*.jpg") {
|
} elseif ("$filename" -like "IMG-*-*.jpg") {
|
||||||
$array = $filename.split("-")
|
$array = $filename.split("-")
|
||||||
$skipped += CopyFile "$file" "$targetDir" $array[1] "$filename"
|
$skipped += CopyPhoto "$file" "$targetDir" $array[1] "$filename"
|
||||||
} elseif ("$filename" -like "PANO_*_*.jpg") {
|
} elseif ("$filename" -like "PANO_*_*.jpg") {
|
||||||
$array = $filename.split("_")
|
$array = $filename.split("_")
|
||||||
$skipped += CopyFile "$file" "$targetDir" $array[1] "$filename"
|
$skipped += CopyPhoto "$file" "$targetDir" $array[1] "$filename"
|
||||||
} elseif ("$filename" -like "PANO-*-*.jpg") {
|
} elseif ("$filename" -like "PANO-*-*.jpg") {
|
||||||
$array = $filename.split("-")
|
$array = $filename.split("-")
|
||||||
$skipped += CopyFile "$file" "$targetDir" $array[1] "$filename"
|
$skipped += CopyPhoto "$file" "$targetDir" $array[1] "$filename"
|
||||||
} elseif ("$filename" -like "SAVE_*_*.jpg") {
|
} elseif ("$filename" -like "SAVE_*_*.jpg") {
|
||||||
$array = $filename.split("_")
|
$array = $filename.split("_")
|
||||||
$skipped += CopyFile "$file" "$targetDir" $array[1] "$filename"
|
$skipped += CopyPhoto "$file" "$targetDir" $array[1] "$filename"
|
||||||
} elseif ("$filename" -like "PXL_*_*.jpg") {
|
} elseif ("$filename" -like "PXL_*_*.jpg") {
|
||||||
$array = $filename.split("_")
|
$array = $filename.split("_")
|
||||||
$skipped += CopyFile "$file" "$targetDir" $array[1] "$filename"
|
$skipped += CopyPhoto "$file" "$targetDir" $array[1] "$filename"
|
||||||
} else {
|
} else {
|
||||||
Write-Host "⏳ Skipping $filename with unknown filename format..."
|
Write-Host "⏳ Skipping $filename with unknown filename format..."
|
||||||
$skipped++
|
$skipped++
|
||||||
@ -88,7 +89,7 @@ try {
|
|||||||
}
|
}
|
||||||
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
[int]$copied = $files.Count - $skipped
|
[int]$copied = $files.Count - $skipped
|
||||||
"✅ Copied $copied photos to 📂$targetDir in $($elapsed)s ($skipped skipped)."
|
"✅ $copied photos copied to 📂$targetDir in $($elapsed)s ($skipped skipped)."
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user