Repository navigation
Expand file tree
/
Copy pathCopy-ArwWithXmp.ps1
More file actions
148 lines (114 loc) · 4.39 KB
/
Copy pathCopy-ArwWithXmp.ps1
File metadata and controls
148 lines (114 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<#
.SYNOPSIS
Copies Sony ARW files together with their matching XMP sidecar files.
.DESCRIPTION
This function scans a source folder for .xmp files and checks whether each one has
a matching .ARW file with the same base filename.
By default, the function only previews what would be copied.
Use the -Copy switch to actually copy both the .xmp and .ARW files.
This is useful after selecting/editing photos in Lightroom, where only selected
photos have matching XMP sidecar files.
.PARAMETER SourceFolder
The folder containing the original ARW and XMP files.
.PARAMETER TargetFolder
The folder where the matched ARW and XMP files should be copied.
.PARAMETER Copy
Actually copies the files. Without this switch, the function only previews what
would be copied.
.EXAMPLE
Copy-ArwWithXmp `
-SourceFolder "D:\DCIM\10460606" `
-TargetFolder "F:\photo\2026\06\20260606-PyDataLondon\104"
Preview files that would be copied from one camera folder.
.EXAMPLE
Copy-ArwWithXmp `
-SourceFolder "D:\DCIM\10460606" `
-TargetFolder "F:\photo\2026\06\20260606-PyDataLondon\104" `
-Copy
Copy matched ARW and XMP files from one camera folder.
.EXAMPLE
$folders = 100..108
foreach ($folder in $folders) {
$source = "D:\DCIM\$folder`60606"
$target = "F:\photo\2026\06\20260606-PyDataLondon\$folder"
Copy-ArwWithXmp -SourceFolder $source -TargetFolder $target
}
Preview matched ARW and XMP files across folders 10060606 to 10860606.
.EXAMPLE
$folders = 100..108
foreach ($folder in $folders) {
$source = "D:\DCIM\$folder`60606"
$target = "F:\photo\2026\06\20260606-PyDataLondon\$folder"
# Preview first:
# Copy-ArwWithXmp -SourceFolder $source -TargetFolder $target
# Copy for real:
Copy-ArwWithXmp -SourceFolder $source -TargetFolder $target -Copy
}
Copy matched ARW and XMP files across folders 10060606 to 10860606.
.NOTES
The folder expression "$folder`60606" uses a backtick to separate the variable name
from the following numbers. This avoids PowerShell interpreting the whole string
incorrectly when building paths such as 10460606.
#>
function Copy-ArwWithXmp {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$SourceFolder,
[Parameter(Mandatory)]
[string]$TargetFolder,
[switch]$Copy
)
if (-not (Test-Path $SourceFolder)) {
throw "Source folder does not exist: $SourceFolder"
}
$xmpFiles = Get-ChildItem -Path $SourceFolder -Filter "*.xmp" -File
$pairs = foreach ($xmp in $xmpFiles) {
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($xmp.Name)
$arwPath = Join-Path $SourceFolder "$baseName.ARW"
if (Test-Path $arwPath) {
[pscustomobject]@{
BaseName = $baseName
XmpSource = $xmp.FullName
ArwSource = $arwPath
XmpTarget = Join-Path $TargetFolder $xmp.Name
ArwTarget = Join-Path $TargetFolder "$baseName.ARW"
Status = if ($Copy) { "Will copy" } else { "Preview only" }
}
}
else {
[pscustomobject]@{
BaseName = $baseName
XmpSource = $xmp.FullName
ArwSource = $null
XmpTarget = $null
ArwTarget = $null
Status = "Missing ARW"
}
}
}
$pairs | Format-Table BaseName, Status, XmpSource, ArwSource, XmpTarget, ArwTarget -AutoSize
$validPairs = $pairs | Where-Object { $_.Status -ne "Missing ARW" }
Write-Host ""
Write-Host "Summary:"
Write-Host "XMP files found: $($xmpFiles.Count)"
Write-Host "Valid ARW/XMP pairs: $($validPairs.Count)"
Write-Host "Missing ARW files: $(($pairs | Where-Object Status -eq 'Missing ARW').Count)"
Write-Host "Files to copy: $($validPairs.Count * 2)"
if ($Copy) {
if (-not (Test-Path $TargetFolder)) {
New-Item -Path $TargetFolder -ItemType Directory -Force | Out-Null
}
foreach ($pair in $validPairs) {
Copy-Item -Path $pair.XmpSource -Destination $pair.XmpTarget -Force
Copy-Item -Path $pair.ArwSource -Destination $pair.ArwTarget -Force
}
Write-Host ""
Write-Host "Copied $($validPairs.Count * 2) files to:"
Write-Host $TargetFolder
}
else {
Write-Host ""
Write-Host "Preview only. Add -Copy to copy the files."
}
}