$source = "D:\Pictures\iCloud Photos\Photos"
$destination = "E:\20240526 iPhone 14 Pro Max"
$files = Get-ChildItem -Path $source -File -Recurse
$totalFiles = $files.Count
$count = 0
foreach ($file in $files) {
$relativePath = $file.FullName.Substring($source.Length)
$destPath = Join-Path -Path $destination -ChildPath $relativePath
$destDir = Split-Path -Path $destPath -Parent
if (-not (Test-Path -Path $destDir)) {
New-Item -Path $destDir -ItemType Directory | Out-Null
}
Copy-Item -LiteralPath $file.FullName -Destination $destPath -Verbose
$count++
Write-Progress -Activity "Copying files" -Status "Copying $count of $totalFiles" -PercentComplete (($count / $totalFiles) * 100)
}
Write-Output "Total files copied: $count"
脚本说明:
-
按创建时间升序排序:使用
Sort-Object -Property CreationTime
对文件进行排序。 -
文件复制和命名:按排序后的文件顺序进行复制,并按照
{序号}_{日期}{文件类型}
的格式进行命名。