Skip to content

Commit

Permalink
Add automation features
Browse files Browse the repository at this point in the history
  • Loading branch information
filipnet committed Jan 5, 2021
1 parent 4586958 commit 20c6905
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 108 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
development
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 2021-05-01 | FEATURE
* Sometimes you have made a lot of photos a day, which you want to copy/move from the memory card and convert afterwards. This was all the time only possible in two steps.
* To be able to do this unattended one after the other, functions for "copy, move and convert" were created in the ``library.ps1``.
* Addition of two new menu items
* Copy RAW/ARW-files from SD-Card & Convert
* Move RAW/ARW-files from SD-Card & Convert

## 2020-05-10 | FEATURE
* Adding function "Delete from memory card"

Expand Down
119 changes: 35 additions & 84 deletions DNGToolKit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Write-Host "Press any key to continue ....."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

# Generate menu
$OptionArray = @("Copy RAW/ARW-files from SD-Card","Move RAW/ARW-files from SD-Card","Convert ARW to DNG","Delete unused RAW/ARW-files","Delete ARW from memory card (attention)","Quit and exit")
$OptionArray = @("Copy RAW/ARW-files from SD-Card","Copy RAW/ARW-files from SD-Card & Convert","Move RAW/ARW-files from SD-Card","Move RAW/ARW-files from SD-Card & Convert","Convert ARW to DNG","Delete unused RAW/ARW-files","Delete ARW from memory card (attention)","Quit and exit")
$Banner = "
DNGToolKit
Latest version: https://github.com/filipnet/dngtoolkit
Expand All @@ -79,103 +79,52 @@ do {
Switch($MenuResult){
0{
# Copy RAW/ARW-files from SD-Card
Write-Host -BackgroundColor Blue "Copy RAW/ARW-files from SD-card"
if (!(Test-Path $src_volume_import)) {
Write-Host -ForegroundColor Red "Please insert SD-card to Volume $($src_volume_import)"
}else{
$arw_files = Get-ChildItem -Recurse "$src_volume_import\*.$src_extension"
$c1 = 0
Clear-Host
foreach ($arw in $arw_files){
$c1++
Write-Progress -Id 0 -Activity 'Copy RAW/ARW-files from SD-Card to convertation directory' -Status "Processing $($c1) of $($arw_files.count)" -CurrentOperation $arw -PercentComplete (($c1/$arw_files.Count) * 100)
Start-Sleep -Milliseconds 200
$x = $arw.LastWriteTime.ToShortDateString()
$new_folder = Get-Date $x -Format yyyy-MM-dd
$dst_path = "$convert_root_path\$($new_folder)\"
if (!(Test-Path $dst_path)) {New-Item -Path $dst_path -ItemType Directory}
Copy-Item $($arw.FullName) -Destination $dst_path
Write-Host -NoNewline "Copying $($arw.FullName) to $($dst_path): "
Write-Host -ForegroundColor Green "OK"
Write-Progress -Activity 'Examining assemblies' -Completed
}
}
Transfer-SDtoDisk -ActionType Copy

[System.Media.SystemSounds]::Beep.Play();
Write-Host "Press any key to continue ....."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}

1{
# Copy RAW/ARW-files from SD-Card & Convert
Transfer-SDtoDisk -ActionType Copy
Convert-ARWtoDNG

[System.Media.SystemSounds]::Beep.Play();
Write-Host "Press any key to continue ....."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}

2{
# Move RAW/ARW-files from SD-Card
Write-Host -BackgroundColor Blue "Move RAW/ARW-files from SD-card"
if (!(Test-Path $src_volume_import)) {
Write-Host -ForegroundColor Red "Please insert SD-card to Volume $($src_volume_import)"
}else{
$arw_files = Get-ChildItem -Recurse "$src_volume_import\*.$src_extension"
$c1 = 0
Clear-Host
foreach ($arw in $arw_files){
$c1++
Write-Progress -Id 0 -Activity 'Move RAW/ARW-files from SD-Card to convertation directory' -Status "Processing $($c1) of $($arw_files.count)" -CurrentOperation $arw -PercentComplete (($c1/$arw_files.Count) * 100)
Start-Sleep -Milliseconds 200
$x = $arw.LastWriteTime.ToShortDateString()
$new_folder = Get-Date $x -Format yyyy-MM-dd
$dst_path = "$convert_root_path\$($new_folder)\"
if (!(Test-Path $dst_path)) {New-Item -Path $dst_path -ItemType Directory}
Move-Item $($arw.FullName) -Destination $dst_path
Write-Host -NoNewline "Moving $($arw.FullName) to $($dst_path): "
Write-Host -ForegroundColor Green "OK"
Write-Progress -Activity 'Examining assemblies' -Completed
}
}
Transfer-SDtoDisk -ActionType Move

[System.Media.SystemSounds]::Beep.Play();
Write-Host "Press any key to continue ....."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}

3{
# Move RAW/ARW-files from SD-Card & Convert
Transfer-SDtoDisk -ActionType Move
Convert-ARWtoDNG

2{
# Convert ARW to DNG
Write-Host -BackgroundColor Blue "Convert ARW to DNG"
$sourceFiles = Get-ChildItem -Path $convert_root_path -Recurse -Include *.$src_extension
if ($sourceFiles.count -eq 0) {
Write-Host -ForegroundColor Red "There are no files to convert in the directory $($convert_root_path)"
Write-Host "Press any key to continue ....."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}else{
$c1 = 0
Clear-Host
ForEach ($file in $sourceFiles) {
$c1++
Write-Progress -Id 0 -Activity 'Converting ARW to DNG' -Status "Processing $($c1) of $($sourceFiles.count)" -CurrentOperation $file -PercentComplete (($c1/$sourceFiles.Count) * 100)
Start-Sleep -Milliseconds 200
$fullArgs = $dng_base_args + """$file"""
$process = start-process $dng_exec_bin $fullArgs -Wait -PassThru
if ($process.ExitCode -eq 0)
{
Write-Host -NoNewline "Converted $($file): "
Write-Host -ForegroundColor Green "SUCCESS"
}
else
{
Write-Host -NoNewline "Converted $($file): "
Write-Host -ForegroundColor Red "ERROR OCCURED, TRY AGAIN"
}
Write-Progress -Activity 'Examining assemblies' -Completed
}
[System.Media.SystemSounds]::Beep.Play();
Write-Host "Press any key to continue ....."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}

Write-Host "Move subdirectories to Lighroom workplace directory" -ForegroundColor Cyan
Get-ChildItem -Path $convert_root_path -Recurse | Move-Item -Destination $workplace_root_path
4{
# Convert ARW to DNG
Convert-ARWtoDNG

[System.Media.SystemSounds]::Beep.Play();
Write-Host "Press any key to continue ....."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
[System.Media.SystemSounds]::Beep.Play();
Write-Host "Press any key to continue ....."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}

3{
5{
# Delete unused RAW/ARW-files
Write-Host -BackgroundColor Blue "Delete unused RAW/ARW-files"
$arw = Get-ChildItem -r -force -include *.arw -ErrorAction SilentlyContinue $workplace_root_path | Sort-Object -Unique
Expand All @@ -191,16 +140,16 @@ do {
remove-item $rawFile
}
}

Write-Host "Deleting empty folders" -ForegroundColor Red
Get-ChildItem $workplace_root_path -Recurse | Where-Object{$_.PSIsContainer -and !(Get-ChildItem $_.Fullname -Recurse | Where-Object{!$_.PSIsContainer})} | Format-Table Name,CreationTime,LastAccessTime,LastWriteTime -AutoSize
Remove-EmptyFolders $workplace_root_path

[System.Media.SystemSounds]::Beep.Play();
Write-Host "Press any key to continue ....."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
4{

6{
# Delete ARW from memory card
Write-Host -BackgroundColor Blue "Delete RAW/ARW-files from memory card"
$confirmation = Read-Host -Prompt 'Are you really sure you would like to delete all photos from your memory card? Type YES and press enter'
Expand All @@ -222,13 +171,15 @@ do {
Write-Host "Press any key to continue ....."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
5{

7{
# Quit and exit
exit
}

Default{
# Quit and exit
exit
}
}
} while ($MenuResult -ne 5)
} while ($MenuResult -ne 7)
120 changes: 96 additions & 24 deletions Library.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,104 @@ function Remove-EmptyFolders([string]$folder){
}

function Check-FolderFile{
param(
[Parameter(Mandatory=$false)]
[string]$FileName,
param(
[Parameter(Mandatory=$false)]
[string]$FileName,

[Parameter(Mandatory=$false)]
[string]$FilePath,

[Parameter(Mandatory=$false)]
[string]$FileDescription
)
[Parameter(Mandatory=$false)]
[string]$FilePath,

[Parameter(Mandatory=$false)]
[string]$FileDescription
)

If (!$FileDescription){ $FileDescription=$FileName }
If (!$FilePath){ $FilePath=$PSScriptRoot }
Write-Host -NoNewline "Check $($FileDescription): "
If (Test-Path $FilePath\$FileName) {
Write-Host -ForegroundColor Green "PASSED "
} else {
Write-Host -ForegroundColor Red "FAILED "
If (!$FileName) {
Write-Host -ForegroundColor DarkBlue -NoNewline "$($FilePath) does not exist. "
$confirmation = Read-Host "Should the directory be created for you? [YES/no]"
if ($confirmation -eq 'YES') {
New-Item -Path $FilePath -ItemType Directory
} else {
exit
}
}
}
}

function Transfer-SDtoDisk {
param (
[Parameter(Mandatory, ParameterSetName='ActionType')]
[ValidateSet('Copy','Move')]
[string[]]$ActionType
)
Write-Host -BackgroundColor Blue "$($ActionType) RAW/ARW-files from SD-card"
if (!(Test-Path $src_volume_import)) {
Write-Host -ForegroundColor Red "Please insert SD-card to Volume $($src_volume_import)"
[System.Media.SystemSounds]::Beep.Play();
Write-Host "Press any key to continue ....."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
} else {
$arw_files = Get-ChildItem -Recurse "$src_volume_import\*.$src_extension"
$c1 = 0
Clear-Host
foreach ($arw in $arw_files){
$c1++
Write-Progress -Id 0 -Activity "$($ActionType) RAW/ARW-files from SD-Card to convertation directory" -Status "Processing $($c1) of $($arw_files.count)" -CurrentOperation $arw -PercentComplete (($c1/$arw_files.Count) * 100)
Start-Sleep -Milliseconds 200
$x = $arw.LastWriteTime.ToShortDateString()
$new_folder = Get-Date $x -Format yyyy-MM-dd
$dst_path = "$convert_root_path\$($new_folder)\"
if (!(Test-Path $dst_path)) {New-Item -Path $dst_path -ItemType Directory}
if ($ActionType -eq "Copy") {
Copy-Item $($arw.FullName) -Destination $dst_path
Write-Host -NoNewline "$($ActionType) $($arw.FullName) to $($dst_path): "
Write-Host -ForegroundColor Green "OK"
Write-Progress -Activity 'Examining assemblies' -Completed
}
if ($ActionType -eq "Move") {
Move-Item $($arw.FullName) -Destination $dst_path
Write-Host -NoNewline "$($ActionType) $($arw.FullName) to $($dst_path): "
Write-Host -ForegroundColor Green "OK"
Write-Progress -Activity 'Examining assemblies' -Completed
}
}
}
}

If (!$FileDescription){ $FileDescription=$FileName }
If (!$FilePath){ $FilePath=$PSScriptRoot }
Write-Host -NoNewline "Check $($FileDescription): "
If (Test-Path $FilePath\$FileName) {
Write-Host -ForegroundColor Green "PASSED "
}else{
Write-Host -ForegroundColor Red "FAILED "
If (!$FileName) {
Write-Host -ForegroundColor DarkBlue -NoNewline "$($FilePath) does not exist. "
$confirmation = Read-Host "Should the directory be created for you? [YES/no]"
if ($confirmation -eq 'YES') {
New-Item -Path $FilePath -ItemType Directory
} else {
exit
}
function Convert-ARWtoDNG {
Write-Host -BackgroundColor Blue "Convert ARW to DNG"
$sourceFiles = Get-ChildItem -Path $convert_root_path -Recurse -Include *.$src_extension
if ($sourceFiles.count -eq 0) {
Write-Host -ForegroundColor Red "There are no files to convert in the directory $($convert_root_path)"
} else {
$c1 = 0
Clear-Host
ForEach ($file in $sourceFiles) {
$c1++
Write-Progress -Id 0 -Activity 'Converting ARW to DNG' -Status "Processing $($c1) of $($sourceFiles.count)" -CurrentOperation $file -PercentComplete (($c1/$sourceFiles.Count) * 100)
Start-Sleep -Milliseconds 200
$fullArgs = $dng_base_args + """$file"""
$process = start-process $dng_exec_bin $fullArgs -Wait -PassThru
if ($process.ExitCode -eq 0)
{
Write-Host -NoNewline "Converted $($file): "
Write-Host -ForegroundColor Green "SUCCESS"
}
else
{
Write-Host -NoNewline "Converted $($file): "
Write-Host -ForegroundColor Red "ERROR OCCURED, TRY AGAIN"
}
Write-Progress -Activity 'Examining assemblies' -Completed
}

Write-Host "Move subdirectories to Lighroom workplace directory" -ForegroundColor Cyan
Get-ChildItem -Path $convert_root_path -Recurse | Move-Item -Destination $workplace_root_path
}
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

Automatic conversion of multiple RAW/ARW files to DNG format with Adobe DNG Converter via PowerShell

## LATEST UPDATE
New Features added for automation in 2021:
* Copy RAW/ARW-files from SD-Card & Convert
* Move RAW/ARW-files from SD-Card & Convert

## REQUIREMENTS

- PowerShell version 3 and above
Expand Down
Binary file added images/dngtoolkit-logo-water.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dngtoolkit-logo-water.psd
Binary file not shown.

0 comments on commit 20c6905

Please sign in to comment.