我从这个网站上借用了代码,它看起来对我作为摄影师很有帮助。由于我不知道PowerShell,我想问一下这段代码是否看起来不错。我不想错误地丢失我的照片。
$source_to_use_as_reference = "C:photosmytrip_to_hawaiBest"
$destination_to_copy = "C:photosmytrip_to_hawaiBestBest_CR2"
$location_to_find_CR2_files = "C:photosmytrip_to_hawaiCR2"
# these are the codes to find CR2 files that matches with JPG files and copy
# them to new destination
cls
$count_all = 0
$count_matches = 0
$a = Get-ChildItem -Path $source_to_use_as_reference -Recurse -File
foreach ($item in $a) {
$count_all += 1
if ($item.Name -match "JPG") {
$name_as_CR2 = $item.Name.Replace('JPG','CR2')
$location_and_cr2_name = $location_to_find_CR2_files + $name_as_CR2
if (Test-Path -Path $location_and_cr2_name ) {
$destination_and_CR2_name = $destination_to_copy + $name_as_CR2
if (Test-Path -Path $destination_and_CR2_name) {
Write-Output "already exists I skipped ... " $destination_and_CR2_name
} else {
$count_matches += 1
Write-Host "I found it " $destination_and_CR2_name
Copy-Item -Path $location_and_cr2_name -Destination $destination_to_copy
}
} else {
}
}
}
Write-Output "$count_matches matches found and files copied to destination $destination_to_copy"
该脚本中没有任何险恶之处,它只是识别、计数并将 JPG 和 CR2 文件复制到第二个位置。