Last active
January 15, 2024 21:39
-
-
Save kosmiq/a125f3f696156eac0b2b3540c4dd5ace to your computer and use it in GitHub Desktop.
PowerShell script for moving RAW-files with no accompanying JPG-files
This file contains hidden or 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
# Simple PowerShell script to iterate files in a folder, look for the defined RAW-file extension and see if it has an accompanying .JPG-file | |
# If it does not, move it into the "clean"-folder | |
# Create folder selector | |
Add-Type -AssemblyName System.Windows.Forms | |
$browser = New-Object System.Windows.Forms.FolderBrowserDialog | |
$null = $browser.ShowDialog() | |
# Store selected path in var | |
$path = $browser.SelectedPath | |
# Set the RAW extension used | |
$rawExtension = ".ARW" | |
$jpgExtension = ".JPG" | |
# Set folder for moving RAW files with no JPG | |
$bkpFolder = "$path\!clean" | |
# Create folder if it does not exists | |
If (!(test-path -PathType container $bkpFolder)) { | |
Write-Output "No clean folder, creating" | |
New-Item -ItemType Directory -Path $bkpFolder | |
} | |
# Iterate files in the selected folder | |
Get-ChildItem -Path $path | ForEach-Object { | |
# Get filename without extension | |
$baseName = $_.BaseName | |
# Get the extension of the file | |
$extension = $_.Extension | |
# If the extension ois the same as our defined extension (line 9 $rawExtension) | |
if ($extension -eq $rawExtension) { | |
# Check if a JPG with the same name exists | |
if ((Test-Path "$path\$baseName$jpgExtension")) { | |
# And do nothing except output that no action will be taken | |
Write-Output "$baseName$jpgExtension and $baseName$rawExtension exists, no action taken" | |
} | |
else { | |
# If no JPG exists, move the RAW file into the clean-folder and output a message | |
Move-Item -Path $_ -Destination $bkpFolder | |
Write-Output "No $jpgExtension exists, moving $baseName$rawExtension to clean folder" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment