Skip to content

Instantly share code, notes, and snippets.

@MoriTanosuke
Last active November 10, 2018 13:46
Show Gist options
  • Save MoriTanosuke/4608be2118c6436480e963f56d1f1758 to your computer and use it in GitHub Desktop.
Save MoriTanosuke/4608be2118c6436480e963f56d1f1758 to your computer and use it in GitHub Desktop.
Simple script to copy Flickr data export files into albums
$count = 0
$all = Get-ChildItem "." -Filter "photo_*.json"
Write-Progress -Activity "Copied" -PercentComplete 0
$all |
Foreach-Object {
$count += 1
$perc = $count / $all.Length
if($count % 50 -eq 0) {
Write-Progress -Activity "Copied" -PercentComplete $perc
Write-Host $count "/" $all.Length "$perc%"
}
$jsondata = Get-Content -Raw -Path $_ | ConvertFrom-Json
$filename = "*" + $jsondata.id + "_o.*"
$file = Get-ChildItem -Path .. -Filter $filename
if(![System.IO.File]::Exists($file.FullName)) {
$msg = "File $filename does not exist"
Write-Output $msg | Out-File -Append "error.txt"
} else {
if($jsondata.albums) {
$directory = "..\albums\" + $jsondata.albums[0].title
} else {
$directory = "..\albums\none"
}
# copy file into directory
$targetFile = "$directory\" + $file.Name
$msg = $file.FullName + "--> $targetFile"
Write-Output $msg | Out-File -Append "copied.txt"
New-Item -ItemType Directory -Force -Path $directory | Out-Null
Copy-Item -Path $file.FullName $targetFile | Out-Null
}
Write-Progress -Activity "Copied" -PercentComplete 100 -Completed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment