Last active
June 5, 2024 18:57
-
-
Save philippgitpush/0f7a5c2613d7c364b6baf7b3352bf820 to your computer and use it in GitHub Desktop.
PowerShell script for organizing JPG files into corresponding folders within the 'JPG' directory, based on the presence of matching DNG files in the 'RAW' directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Path to the current directory | |
$baseFolder = Get-Location | |
# Path to the JPG folder | |
$jpgFolder = Join-Path $baseFolder "JPG" | |
# Path to the RAW folder | |
$rawFolder = Join-Path $baseFolder "RAW" | |
# Iterate through all .jpg files in the JPG folder | |
foreach ($jpgFile in Get-ChildItem "$jpgFolder\*.jpg") { | |
# Extract the file name without extension | |
$jpgFileName = $jpgFile.BaseName | |
# Check if a .dng file with the same name (excluding the file path) exists in the RAW folder | |
$rawDngFile = Get-ChildItem "$rawFolder\*\*.dng" | Where-Object { $_.BaseName -eq $jpgFileName } | |
if ($rawDngFile) { | |
# Extract the subfolder in the RAW folder where the .dng file is located | |
$rawSubFolder = $rawDngFile.Directory.FullName.Replace($rawFolder, "") | |
# Create paths for the destination folders | |
$destinationFolder = Join-Path $jpgFolder $rawSubFolder | |
$destinationPath = Join-Path $destinationFolder "$jpgFileName.jpg" | |
# Ensure that the destination folder exists | |
if (-not (Test-Path -Path $destinationFolder)) { | |
New-Item -ItemType Directory -Path $destinationFolder | Out-Null | |
} | |
# Move the .jpg file to the corresponding folder in the JPG folder | |
Move-Item $jpgFile.FullName $destinationPath | |
Write-Host "Moved: $($jpgFile.FullName) -> $($destinationPath)" | |
} | |
else { | |
Write-Host "No matching .dng file found for $($jpgFile.FullName)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example input
Example output