AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

delete RAW.ahk (photo)

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
kardus



Joined: 17 Jul 2008
Posts: 14

PostPosted: Wed Aug 06, 2008 8:43 pm    Post subject: delete RAW.ahk (photo) Reply with quote

Code:
; This script to delete photo in RAW format (.CR2 for canon Eos 20D)
; when in a folder there are file RAW that are isolated, that have no corresponding .JPG (and no other files with
; the same name exist, that means no work in progess with it), they are considered to be deleted
; for example, after shooting with my camera I get the following files:
; 2008-4-13 001.JPG
; 2008-4-13 001.CR2
; 2008-4-13 002.JPG
; 2008-4-13 002.CR2
; 2008-4-13 003.JPG
; 2008-4-13 003.CR2
; 2008-4-13 004.JPG
; 2008-4-13 004.CR2
; etc ........
; later I decide which photo to keep reviewing the JPG: if are not good I cancel it. When terminated the
; associated .CR2 are still there and need to be removed, but only that haven't associated .JPG
; Just run this script in the directory where the photo reside
; For my needs (safety reason) this is done only if the directory and the files have a date structure (e.g. 2007-5-30...)
; For months with 2 digit, october, november, december, letter a, b, c, are used (2007-a-30 means 30 october 2007, and so on)

base_raw =
deleted =
elapsed_time =
ext =
start_time =

; to set the extension for various type of RAW, just add lines below:
raw1 = cr2   ; canon Eos20D
raw2 = crw   ; canon D300
raw3 =
raw4 =
raw5 =

SetWorkingDir %A_ScriptDir%
#SingleInstance ignore         ; attempts to launch an already-running script are ignored


; _______________________________________________ check directory validity ___________________________________
; the date portion (e.g. 2007-5-30) of the directory is extractd (only 9 character that are date)
dir_right := SubStr(A_ScriptDir, InStr(A_ScriptDir, "\", false, 0)+1, 9)

; safety: if the dir is not of kind "2007-5-30 ...", that is 5° and 7° character "-", 8° and 9° between 1 and 31
; the script terminate immediatly
if SubStr(dir_right, 5, 1) <> "-" or SubStr(dir_right, 7, 1) <> "-" or SubStr(dir_right, 8 , 2)*1 < 1 or SubStr(dir_right, 8 , 2)*1 > 31
 {MsgBox 64,, %dir_right%`nNOT a valid directory, 1.5
  ExitApp
 }

MsgBox 4,, Do you really want to delete isolated RAW?`n(press Yes or No)
IfMsgBox No
 ExitApp

BlockInput on
start_time := A_TickCount   ; variabile to calcolate elapsed_time when the sript terminate
CoordMode ToolTip
ToolTip `n wait... deleting RAW `n`n (BlockInput)`n, (A_ScreenWidth/4), (A_ScreenHeight/4), 3


; _______________________________________________ search for and delete isolated RAW _________________________
Loop
{
if raw%A_Index% =
 break
else ext := raw%A_Index%
;msgbox ,,, ext %ext%, 1
Loop %dir_right%*.%ext%    ; string comparisons are not case sensitive, see: StringCaseSense
 {
  StringTrimRight base_raw, A_LoopFileName, 4
  Loop %base_raw%*.*               ; with the RAW found above, we search for any file with same name and different extension
   {
    ;if A_LoopFileExt = xmp        ; if you need that also with .XMP (sidecar file), the RAW is still considered isolated thus eligible for deletion (add FileMove for that .XMP in the proper line below)
    ;  continue
    if A_LoopFileExt <> %ext%      ; search successful, the RAW is not isolated and not to be deleted
      base_raw =
   }
  ;msgbox ,,, base_raw (%base_raw%)`nA_LoopFileName (%A_LoopFileName%), 1
  if base_raw <>
   {deleted += 1
    ;msgbox ,,, deleting %A_LoopFileName%, 1
    IfNotExist C:\_RAW
     {
      FileCreateDir C:\_RAW
      FileAppend ,, C:\_RAW\__it is possible to delete this dir, will be created again if necessary__
     }
    ;filecopy %A_LoopFileName%, C:\_RAW\%A_LoopFileName%    ; test only
    ; deleting isolated RAW (for safety moved to C:\_RAW, with timestamp added)
    filemove %A_LoopFileName%, C:\_RAW\%base_raw% (%A_YYYY%-%A_MM%-%A_DD%_h%A_Hour%.%A_Min%.%A_Sec%).%A_LoopFileExt%
    if ErrorLevel
      Msgbox ,,, Error in moving %A_LoopFileName%, 2
   }
  ;else msgbox skip %A_LoopFileName%
 }
}
elapsed_time := Round((A_TickCount - start_time) / 1000, 1)
;MsgBox  64,, `nExitApp`n`nRAW deleted (%deleted%)`nin %elapsed_time% sec., 0.9
;SplashTextOn 200, 200, %A_ScriptName%, `nExitApp`n`nRAW deleted (%deleted%)`nin %elapsed_time% sec.
Progress zh0 fs12, ExitApp`nRAW deleted (%deleted%)`nin %elapsed_time% sec.
sleep 1000
ExitApp
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Oct 26, 2008 1:25 am    Post subject: Reply with quote

it would be neat to wrap rename photo.ahk with this script or vice-versa.
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group