Jump to content

View images in XnView and move them to subdirectories by pressing a key


Recommended Posts

;)Change log:

Here, it takes a FEW seconds to load because of the hotkey assignments am guessing and is not very organized. I am feeling lazy now, when it just works. You'll probably be surprised when you try it. I do not know how performance will be affected when you manage to 'tag' 1000 images, or some other huge number, since the script performs an array search (on full file path for now because am lazy) to check if current image is already tagged. ;)

I added timers to see how long it takes to perform some actions, while I was comparing performance of the two scripts.

:unsure:Known Bugs:

There might be a glitch if user types when there are CAPS in the folder name, and shift key gets stuck in the down state. :)

:)Why I like it:

I really like the idea that you can sort your images by pressing ONE key, not having to load every stinkin' image into a realllllllly slow program such as Picasa or My Photo Index, to only find out that you have to type your tags each time, or drag a tag onto each photo within a poorly designed GUI, AFTER those programs display EVERY single filename and/or image you are importing, thus slowing down the import to a crawl. Smart programmers? I think not. It surprises me that no program allows you to do what this post mentions. I am going to make a script to work with XnView. :>

XnView is a robust solution, as opposed to windows picture and fax viewer to display images quickly. Also, XnView can display full file path in the title bar, unlike windows picture and fax viewer.

:DRequirements:

Full file path should be set under

Tools>Options>View>Title Bar: <Directory><Filename With Ext>

Title should look like this: XnView - [K:\random pics\c33a32.jpg]

Also in XnView you must set keyboard/mouse to use left/right arrow keys to move between files, which I might include in the script later on.

Tools>Options>General:Keyboard/Mouse>Cursor Left/Right>Previous/Next File

To use Flavor 1, you must get the OnEventFunc UDF and throw it into AutoIt's Include dir.

(LINK)OnEventFunc Downloader which came from

; ImgTag.au3 Flavor 1 by SmartiePants, implementing OnEventFunc UDF by Martin Gibson (martin)
; OnEventFunc is a UDF to allow onevent or HotKeys to be used to call functions with parameters.
; For thread where this udf is posted, see
; http://www.autoitscript.com/forum/topic/71811-functions-with-parameters-in-onevent-and-hotkeys
; 
; designed to work within one photo dir per task
; multiple dirs will result something like this - K:\dir1\file1.jpg and K:\dir2\file2.jpg moved to K:\dir1\x\file1.jpg and K:\dir2\x\file2.jpg
; you CAN type outside of the program, but don't do it too fast if you want to avoid keystrokes you didn't intend for.
#include <onEventFunc.au3>
$tstart = TimerInit()
Opt("WinTitleMatchMode", 2) ; 2 = Match any substring in the title
Global $sWinTitle = "", $moveto = "", $pos = 0, $ini = @ScriptDir & "\ImgTag.ini" ; declare vars

If Not FileExists($ini) Then _iniCreate(); create .ini if it doesn't exist

If Not WinExists("XnView -") Then ; exit if XnView isn't running
    MsgBox(48, "Error 2", "You should have XnView running.")
    Exit 1
EndIf
If Not WinActive("XnView -") Then ; bring XnView forward if it's elsewhere
    WinActivate("XnView -")
    WinWaitActive("XnView -")
EndIf

$aKeys = IniReadSection($ini, "Main") ; read all .ini entries that contain '='
For $i = 1 To $aKeys[0][0] - 1 ; clear invalid entries, do not use _ArrayDelete, since it causes ExitLoop
    If StringLeft($aKeys[$i][0], 1) = "#" Then
        $aKeys[$i][0] = ""
        $aKeys[$i][1] = ""
    EndIf
Next
BlockInput(1)
For $i = 1 To $aKeys[0][0] - 1 ; set hotkeys
    Switch $aKeys[$i][0]
        Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
            SetOnEventA($aKeys[$i][0], "_hotkey", $ParamByVal, $aKeys[$i][1])
        Case "next_key"
            Global $next_key = $aKeys[$i][1]
            HotKeySet($next_key, "_next")
        Case "previous_key" ; no next_previous_display because it's not shown
            Global $previous_key = $aKeys[$i][1]
            HotKeySet($previous_key, "_previous")
        Case "next_previous_display" ; shown to make the user use right and left arrows
            Global $next_previous_display = $aKeys[$i][1]
        Case "move_photos_key"
            Global $move_photos_key = $aKeys[$i][1]
            HotKeySet($move_photos_key, "_move")
        Case "move_photos_key_display"
            Global $move_photos_key_display = $aKeys[$i][1]
    EndSwitch
Next
BlockInput(0)

; Initialize array
Local $array[10][2] ; create 2D array that is incremented by 10 elements at a time
$array[0][0] = 0 ; [0][0] = count
$array[0][1] = UBound($array) ; [0][1] = limit
Const $oConst = $array[0][1]
$telapsed = TimerDiff($tstart)
ToolTip("Started in " & Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | to display next/previous image - " & $next_previous_display, 300, 0)
While 1 ; run until Moving Execution
    Sleep(100)
WEnd

Func _next()
    If WinActive("XnView - [") Then
        BlockInput(1)
        $tstart = TimerInit()
        $pos = 0
        HotKeySet($next_key) ; temporarily disable
        Send("{RIGHT}")
        HotKeySet($next_key, "_next")
        For $a = $array[0][0] To 1 Step -1
            $sWinTitle = WinGetTitle("XnView -") ; Get full title of the photo viewer window
            If Not $sWinTitle = 0 Then ; if XnView is running and a file is open...
                $sWinTitle = StringSplit($sWinTitle, " - [", 1) ; output = filename.jpg]
                $sWinTitle = StringLeft($sWinTitle[2], StringLen($sWinTitle[2]) - 1) ; output = filename.jpg
                If $array[$a][0] = $sWinTitle Then
                    $pos = $a
                    $locFileName = StringInStr($array[$a][0], "\", 2, -1)
                    ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($array[$pos][0], StringLen($array[$pos][0]) - $locFileName) & " | " & $array[$pos][1], 300, 0)
                    ExitLoop
                EndIf
            EndIf
        Next
        If $pos = 0 Then ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0)
        BlockInput(0)
    EndIf
EndFunc   ;==>_next
Func _previous()
    If WinActive("XnView - [") Then
        BlockInput(1)
        $tstart = TimerInit()
        $pos = 0
        HotKeySet("{LEFT}") ; temporarily disable
        Send("{LEFT}")
        HotKeySet("{LEFT}", "_previous")
        For $a = $array[0][0] To 1 Step -1
            $sWinTitle = WinGetTitle("XnView -") ; Get full title of the photo viewer window
            If Not $sWinTitle = 0 Then ; if XnView is running and a file is open...
                $sWinTitle = StringSplit($sWinTitle, " - [", 1) ; output = filename.jpg]
                $sWinTitle = StringLeft($sWinTitle[2], StringLen($sWinTitle[2]) - 1) ; output = filename.jpg
                If $array[$a][0] = $sWinTitle Then
                    $pos = $a
                    $locFileName = StringInStr($array[$a][0], "\", 2, -1)
                    ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($array[$pos][0], StringLen($array[$pos][0]) - $locFileName) & " | " & $array[$pos][1], 300, 0)
                    ExitLoop
                EndIf
            EndIf
        Next
        If $pos = 0 Then ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0)
        BlockInput(0)
    EndIf
EndFunc   ;==>_previous

Func LogFile($moveto)
    BlockInput(1)
    $tstart = TimerInit()
    $sWinTitle = WinGetTitle("XnView - [") ; Get the full title of the photo viewer window
    If Not StringInStr($sWinTitle, "\]", 2) Then ; if XnView is running and a file is open...
        If StringInStr($sWinTitle, ":") Then ; if file path is shown in the title bar...
            $sWinTitle = StringSplit($sWinTitle, " - [", 1) ; output = filename.jpg]
            $sWinTitle = StringLeft($sWinTitle[2], StringLen($sWinTitle[2]) - 1) ; output = filename.jpg
            $locFileName = StringInStr($sWinTitle, "\", 2, -1)
            If $array[$array[0][0]][0] = $sWinTitle And $array[$array[0][0]][1] = $moveto Then ; erase tag if setting second time the same, last entry
                $array[$array[0][0]][0] = ""
                $array[$array[0][0]][1] = ""
                ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0)
            ElseIf $pos = 0 Then ; if not the same entry, write new entry
                If $array[0][0] = $array[0][1] - 1 Then ; resize array
                    $array[0][1] += $oConst
                    ReDim $array[$array[0][1]][2]
                EndIf
                $array[0][0] += 1 ; write new entry
                $array[$array[0][0]][0] = $sWinTitle
                $array[$array[0][0]][1] = $moveto
                ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($sWinTitle, StringLen($sWinTitle) - $locFileName) & " | " & $moveto, 300, 0)
            Else ; $pos was set, change existing entry
                If $array[$pos][0] = $sWinTitle And $array[$pos][1] = $moveto Then ; erase entry if setting second time the same, not last entry
                    $array[$pos][0] = ""
                    $array[$pos][1] = ""
                    ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0)
                Else ; update existing entry
                    $array[$pos][0] = $sWinTitle
                    $array[$pos][1] = $moveto
                    ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($sWinTitle, StringLen($sWinTitle) - $locFileName) & " | " & $moveto, 300, 0)
                EndIf
                $pos = 0 ; reset existing entry position after updating entry
            EndIf
        Else ; full file path isn't enabled
            BlockInput(0)
            MsgBox(48, "Error 4", "Must display full file path in the title bar:" & @CRLF & "Tools>Options>View>Title Bar: <Directory><Filename With Ext>")
        EndIf
    Else ; image isn't open
        BlockInput(0)
        MsgBox(48, "Error 3", "You should double-click on an image within XnView to cause XnView to display its filename in the title bar.")
    EndIf
    BlockInput(0)
EndFunc   ;==>LogFile

Func _move()
    If $array[0][0] < $array[0][1] Then ; Array trim to valid elements
        ReDim $array[$array[0][0] + 1][2]
    EndIf
    ;_ArrayDisplay($array) ; preview array before moving files for debugging purposes
    For $i = 1 To $array[0][0]
        $locFileName = StringInStr($array[$i][0], "\", 2, -1)
        If FileExists($array[$i][0]) Then ; move all valid files
            $moved = FileMove($array[$i][0], StringLeft($array[$i][0], $locFileName) & "\" & $array[$i][1] & "\" & StringRight($array[$i][0], StringLen($array[$i][0]) - $locFileName), 8) ; 8 = create dir structure
            If $moved = 0 Then
                MsgBox(48, "Error 1", "couldn't move " & $array[$i][0] & @CRLF & "to " & StringLeft($array[$i][0], StringLen($array[$i][0]) - $locFileName) & "\" & $array[$i][1] & "\" & StringRight($array[$i][0], StringLen($array[$i][0]) - $locFileName))
            EndIf
            ToolTip("Moving " & StringRight($sWinTitle, StringLen($sWinTitle) - $locFileName), 300, 0)
        EndIf
    Next
;~  MsgBox(32, "Done?", "Yeah, ImgTag task completed, photos moved.")
    ToolTip("Files moved", 300, 0)
    Exit 0
EndFunc   ;==>_move

Func _hotkey($key);,$b)
    If WinActive("XnView - [") Then
        LogFile($key)
    Else
        Ascii($key)
    EndIf
EndFunc   ;==>_hotkey

Func Ascii($text)
    $aSplit = StringSplit($text, "")
    For $i = 1 To $aSplit[0]
        Local $asc = "{ASC " & Asc($aSplit[$i]) & "}"
        Send($asc)
    Next
EndFunc   ;==>Ascii

Func _iniCreate()
    ToolTip("Creating .INI", 300, 0)
    $iniHanle = FileOpen($ini, 1)
    If $iniHanle = -1 Then
        MsgBox(16, "Error", "Unable to create .INI file")
        Exit 1
    EndIf
    FileWriteLine($iniHanle, "[Main]")
    FileWriteLine($iniHanle, "# to put images into dir '99'")
    FileWriteLine($iniHanle, "# a=99")
    FileWriteLine($iniHanle, "# to put images into dir 'ZOMG'")
    FileWriteLine($iniHanle, "# a=ZOMG")
    FileWriteLine($iniHanle, "# not all hotkeys will be usable, if the program has them assigned internally already.")
    FileWriteLine($iniHanle, "# use right arrow key to move between photos to update tooltip, or change it to w/e you want, such as {SPACE}")
    FileWriteLine($iniHanle, "next_key={RIGHT}")
    FileWriteLine($iniHanle, "previous_key={LEFT}")
    FileWriteLine($iniHanle, "next_previous_display=Left/Right Arrow keys")
    FileWriteLine($iniHanle, "# ^ - control, ! - alt, + - shift")
    FileWriteLine($iniHanle, "move_photos_key=^!y")
    FileWriteLine($iniHanle, "move_photos_key_display=Ctrl+Alt+Y")
    FileWriteLine($iniHanle, "1=1")
    FileWriteLine($iniHanle, "2=2")
    FileWriteLine($iniHanle, "3=3")
    FileWriteLine($iniHanle, "4=4")
    FileWriteLine($iniHanle, "5=5")
    FileWriteLine($iniHanle, "6=6")
    FileWriteLine($iniHanle, "7=7")
    FileWriteLine($iniHanle, "8=8")
    FileWriteLine($iniHanle, "9=9")
    FileWriteLine($iniHanle, "0=0")
    FileWriteLine($iniHanle, "a=a")
    FileWriteLine($iniHanle, "b=b")
    FileWriteLine($iniHanle, "c=c")
    FileWriteLine($iniHanle, "d=d")
    FileWriteLine($iniHanle, "e=e")
    FileWriteLine($iniHanle, "f=f")
    FileWriteLine($iniHanle, "g=g")
    FileWriteLine($iniHanle, "h=h")
    FileWriteLine($iniHanle, "i=i")
    FileWriteLine($iniHanle, "j=j")
    FileWriteLine($iniHanle, "k=k")
    FileWriteLine($iniHanle, "l=l")
    FileWriteLine($iniHanle, "m=m")
    FileWriteLine($iniHanle, "n=n")
    FileWriteLine($iniHanle, "o=o")
    FileWriteLine($iniHanle, "p=p")
    FileWriteLine($iniHanle, "q=q")
    FileWriteLine($iniHanle, "r=r")
    FileWriteLine($iniHanle, "s=s")
    FileWriteLine($iniHanle, "t=t")
    FileWriteLine($iniHanle, "u=u")
    FileWriteLine($iniHanle, "v=v")
    FileWriteLine($iniHanle, "w=w")
    FileWriteLine($iniHanle, "x=x")
    FileWriteLine($iniHanle, "y=y")
    FileWriteLine($iniHanle, "z=z")
    FileClose($iniHanle)
    MsgBox(32, "Should you review .ini?", "Sure, review .ini" & @CRLF & "When done, close notepad to resume script.")
    ShellExecuteWait("Notepad.exe", $ini, @ScriptDir, "open", @SW_MAXIMIZE)EndFunc   ;==>_iniCreate

; ImgTag.au3 Flavor 2 by SmartiePants, implementing @HotKeyPressed
;
; designed to work within one photo dir per task
; multiple dirs will result something like this - K:\dir1\file1.jpg and K:\dir2\file2.jpg moved to K:\dir1\x\file1.jpg and K:\dir2\x\file2.jpg
; you CAN type outside of the program, but don't do it too fast if you want to avoid keystrokes you didn't intend for.
#include <Misc.au3>
$tstart = TimerInit()
Opt("WinTitleMatchMode", 2) ; 2 = Match any substring in the title
Global $sWinTitle = "", $moveto = "", $pos = 0, $ini = @ScriptDir & "\ImgTag.ini" ; declare vars

If Not FileExists($ini) Then _iniCreate(); create .ini if it doesn't exist

If Not WinExists("XnView -") Then ; exit if XnView isn't running
    MsgBox(48, "Error 2", "You should have XnView running.")
    Exit 1
EndIf
If Not WinActive("XnView -") Then ; bring XnView forward if it's elsewhere
    WinActivate("XnView -")
    WinWaitActive("XnView -")
EndIf

$aKeys = IniReadSection($ini, "Main") ; read all .ini entries that contain '='
For $i = 1 To $aKeys[0][0] - 1 ; clear invalid entries, do not use _ArrayDelete, since it causes ExitLoop
    If StringLeft($aKeys[$i][0], 1) = "#" Then
        $aKeys[$i][0] = ""
        $aKeys[$i][1] = ""
    EndIf
Next
BlockInput(1)
For $i = 1 To $aKeys[0][0] - 1 ; set hotkeys
    Switch $aKeys[$i][0]
        Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
            HotKeySet($aKeys[$i][0], "_hotkey") ; set all alphanumeric HotKey presets from .ini
        Case "next_key"
            Global $next_key = $aKeys[$i][1]
            HotKeySet($next_key, "_next")
        Case "previous_key" ; no next_previous_display because it's not shown
            Global $previous_key = $aKeys[$i][1]
            HotKeySet($previous_key, "_previous")
        Case "next_previous_display" ; shown to make the user use right and left arrows
            Global $next_previous_display = $aKeys[$i][1]
        Case "move_photos_key"
            Global $move_photos_key = $aKeys[$i][1]
            HotKeySet($move_photos_key, "_move")
        Case "move_photos_key_display"
            Global $move_photos_key_display = $aKeys[$i][1]
    EndSwitch
Next
BlockInput(0)

; Initialize array
Local $array[10][2] ; create 2D array that is incremented by 10 elements at a time
$array[0][0] = 0 ; [0][0] = count
$array[0][1] = UBound($array) ; [0][1] = limit
Const $oConst = $array[0][1]
ToolTip("Started in " & Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | to display next/previous image - " & $next_previous_display, 300, 0)
While 1 ; run until Moving Execution
    Sleep(100)
WEnd

Func _next()
    If WinActive("XnView - [") Then
        BlockInput(1)
        $tstart = TimerInit()
        $pos = 0
        HotKeySet($next_key) ; temporarily disable
        Send("{RIGHT}")
        HotKeySet($next_key, "_next")
        For $a = $array[0][0] To 1 Step -1
            $sWinTitle = WinGetTitle("XnView -") ; Get full title of the photo viewer window
            If Not $sWinTitle = 0 Then ; if XnView is running and a file is open...
                $sWinTitle = StringSplit($sWinTitle, " - [", 1) ; output = filename.jpg]
                $sWinTitle = StringLeft($sWinTitle[2], StringLen($sWinTitle[2]) - 1) ; output = filename.jpg
                If $array[$a][0] = $sWinTitle Then
                    $pos = $a
                    $locFileName = StringInStr($array[$a][0], "\", 2, -1)
                    ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($array[$pos][0], StringLen($array[$pos][0]) - $locFileName) & " | " & $array[$pos][1], 300, 0)
                    ExitLoop
                EndIf
            EndIf
        Next
        If $pos = 0 Then ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0)
        BlockInput(0)
    EndIf
EndFunc   ;==>_next
Func _previous()
    If WinActive("XnView - [") Then
        BlockInput(1)
        $tstart = TimerInit()
        $pos = 0
        HotKeySet("{LEFT}") ; temporarily disable
        Send("{LEFT}")
        HotKeySet("{LEFT}", "_previous")
        For $a = $array[0][0] To 1 Step -1
            $sWinTitle = WinGetTitle("XnView -") ; Get full title of the photo viewer window
            If Not $sWinTitle = 0 Then ; if XnView is running and a file is open...
                $sWinTitle = StringSplit($sWinTitle, " - [", 1) ; output = filename.jpg]
                $sWinTitle = StringLeft($sWinTitle[2], StringLen($sWinTitle[2]) - 1) ; output = filename.jpg
                If $array[$a][0] = $sWinTitle Then
                    $pos = $a
                    $locFileName = StringInStr($array[$a][0], "\", 2, -1)
                    ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($array[$pos][0], StringLen($array[$pos][0]) - $locFileName) & " | " & $array[$pos][1], 300, 0)
                    ExitLoop
                EndIf
            EndIf
        Next
        If $pos = 0 Then ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0)
        BlockInput(0)
    EndIf
EndFunc   ;==>_previous

Func LogFile($moveto)
    BlockInput(1)
    $tstart = TimerInit()
    $sWinTitle = WinGetTitle("XnView - [") ; Get the full title of the photo viewer window
    If Not StringInStr($sWinTitle, "\]", 2) Then ; if XnView is running and a file is open...
        If StringInStr($sWinTitle, ":") Then ; if file path is shown in the title bar...
            $sWinTitle = StringSplit($sWinTitle, " - [", 1) ; output = filename.jpg]
            $sWinTitle = StringLeft($sWinTitle[2], StringLen($sWinTitle[2]) - 1) ; output = filename.jpg
            $locFileName = StringInStr($sWinTitle, "\", 2, -1)
            If $array[$array[0][0]][0] = $sWinTitle And $array[$array[0][0]][1] = $moveto Then ; erase tag if setting second time the same, last entry
                $array[$array[0][0]][0] = ""
                $array[$array[0][0]][1] = ""
                ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0)
            ElseIf $pos = 0 Then ; if not the same entry, write new entry
                If $array[0][0] = $array[0][1] - 1 Then ; resize array
                    $array[0][1] += $oConst
                    ReDim $array[$array[0][1]][2]
                EndIf
                $array[0][0] += 1 ; write new entry
                $array[$array[0][0]][0] = $sWinTitle
                $array[$array[0][0]][1] = $moveto
                ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($sWinTitle, StringLen($sWinTitle) - $locFileName) & " | " & $moveto, 300, 0)
            Else ; $pos was set, change existing entry
                If $array[$pos][0] = $sWinTitle And $array[$pos][1] = $moveto Then ; erase entry if setting second time the same, not last entry
                    $array[$pos][0] = ""
                    $array[$pos][1] = ""
                    ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | ", 300, 0)
                Else ; update existing entry
                    $array[$pos][0] = $sWinTitle
                    $array[$pos][1] = $moveto
                    ToolTip(Round(TimerDiff($tstart),0) & "ms | " & $move_photos_key_display & " - execute moving | " & StringRight($sWinTitle, StringLen($sWinTitle) - $locFileName) & " | " & $moveto, 300, 0)
                EndIf
                $pos = 0 ; reset existing entry position after updating entry
            EndIf
        Else ; full file path isn't enabled
            BlockInput(0)
            MsgBox(48, "Error 4", "Must display full file path in the title bar:" & @CRLF & "Tools>Options>View>Title Bar: <Directory><Filename With Ext>")
        EndIf
    Else ; image isn't open
        BlockInput(0)
        MsgBox(48, "Error 3", "You should double-click on an image within XnView to cause XnView to display its filename in the title bar.")
    EndIf
    BlockInput(0)
EndFunc   ;==>LogFile

Func _move()
    If $array[0][0] < $array[0][1] Then ; Array trim to valid elements
        ReDim $array[$array[0][0] + 1][2]
    EndIf
    ;_ArrayDisplay($array) ; preview array before moving files for debugging purposes
    For $i = 1 To $array[0][0]
        $locFileName = StringInStr($array[$i][0], "\", 2, -1)
        If FileExists($array[$i][0]) Then ; move all valid files
            $moved = FileMove($array[$i][0], StringLeft($array[$i][0], $locFileName) & "\" & $array[$i][1] & "\" & StringRight($array[$i][0], StringLen($array[$i][0]) - $locFileName), 8) ; 8 = create dir structure
            If $moved = 0 Then
                MsgBox(48, "Error 1", "couldn't move " & $array[$i][0] & @CRLF & "to " & StringLeft($array[$i][0], StringLen($array[$i][0]) - $locFileName) & "\" & $array[$i][1] & "\" & StringRight($array[$i][0], StringLen($array[$i][0]) - $locFileName))
            EndIf
            ToolTip("Moving " & StringRight($sWinTitle, StringLen($sWinTitle) - $locFileName), 300, 0)
        EndIf
    Next
;~  MsgBox(32, "Done?", "Yeah, ImgTag task completed, photos moved.")
    ToolTip("Files moved", 300, 0)
    Exit 0
EndFunc   ;==>_move

Func _hotkey() ; for now repetitive array search
    For $i = 1 To $aKeys[0][0]
        If $aKeys[$i][0] = @HotKeyPressed Then
            Local $dir = $aKeys[$i][1]
            ExitLoop
        EndIf
    Next
    If WinActive("XnView - [") Then
        LogFile($dir)
    Else
        Ascii($dir)
    EndIf
EndFunc   ;==>_hotkey

Func Ascii($text)
    $aSplit = StringSplit($text, "")
    For $i = 1 To $aSplit[0]
        Local $asc = "{ASC " & Asc($aSplit[$i]) & "}"
        Send($asc)
    Next
EndFunc   ;==>Ascii

Func _iniCreate()
    ToolTip("Creating .INI", 300, 0)
    $iniHanle = FileOpen($ini, 1)
    If $iniHanle = -1 Then
        MsgBox(16, "Error", "Unable to create .INI file")
        Exit 1
    EndIf
    FileWriteLine($iniHanle, "[Main]")
    FileWriteLine($iniHanle, "# to put images into dir '99'")
    FileWriteLine($iniHanle, "# a=99")
    FileWriteLine($iniHanle, "# to put images into dir 'ZOMG'")
    FileWriteLine($iniHanle, "# a=ZOMG")
    FileWriteLine($iniHanle, "# not all hotkeys will be usable, if the program has them assigned internally already.")
    FileWriteLine($iniHanle, "# use right arrow key to move between photos to update tooltip, or change it to w/e you want, such as {SPACE}")
    FileWriteLine($iniHanle, "next_key={RIGHT}")
    FileWriteLine($iniHanle, "previous_key={LEFT}")
    FileWriteLine($iniHanle, "next_previous_display=Left/Right Arrow keys")
    FileWriteLine($iniHanle, "# ^ - control, ! - alt, + - shift")
    FileWriteLine($iniHanle, "move_photos_key=^!y")
    FileWriteLine($iniHanle, "move_photos_key_display=Ctrl+Alt+Y")
    FileWriteLine($iniHanle, "1=1")
    FileWriteLine($iniHanle, "2=2")
    FileWriteLine($iniHanle, "3=3")
    FileWriteLine($iniHanle, "4=4")
    FileWriteLine($iniHanle, "5=5")
    FileWriteLine($iniHanle, "6=6")
    FileWriteLine($iniHanle, "7=7")
    FileWriteLine($iniHanle, "8=8")
    FileWriteLine($iniHanle, "9=9")
    FileWriteLine($iniHanle, "0=0")
    FileWriteLine($iniHanle, "a=a")
    FileWriteLine($iniHanle, "b=b")
    FileWriteLine($iniHanle, "c=c")
    FileWriteLine($iniHanle, "d=d")
    FileWriteLine($iniHanle, "e=e")
    FileWriteLine($iniHanle, "f=f")
    FileWriteLine($iniHanle, "g=g")
    FileWriteLine($iniHanle, "h=h")
    FileWriteLine($iniHanle, "i=i")
    FileWriteLine($iniHanle, "j=j")
    FileWriteLine($iniHanle, "k=k")
    FileWriteLine($iniHanle, "l=l")
    FileWriteLine($iniHanle, "m=m")
    FileWriteLine($iniHanle, "n=n")
    FileWriteLine($iniHanle, "o=o")
    FileWriteLine($iniHanle, "p=p")
    FileWriteLine($iniHanle, "q=q")
    FileWriteLine($iniHanle, "r=r")
    FileWriteLine($iniHanle, "s=s")
    FileWriteLine($iniHanle, "t=t")
    FileWriteLine($iniHanle, "u=u")
    FileWriteLine($iniHanle, "v=v")
    FileWriteLine($iniHanle, "w=w")
    FileWriteLine($iniHanle, "x=x")
    FileWriteLine($iniHanle, "y=y")
    FileWriteLine($iniHanle, "z=z")
    FileClose($iniHanle)
    MsgBox(32, "Should you review .ini?", "Sure, review .ini" & @CRLF & "When done, close notepad to resume script.")
    ShellExecuteWait("Notepad.exe", $ini, @ScriptDir, "open", @SW_MAXIMIZE)
EndFunc   ;==>_iniCreate
Edited by SmartiePants

[font="Comic Sans MS"]It's my first day.[/font]View and move images to subdirectories by pressing a key in XnView

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...