Jump to content

Digital Camera jpg renamer


Ejoc
 Share

Recommended Posts

This speeds up renaming all those DSCxxxxx.jpg digital pictures to a useful filename. Select all the DSC files and it will display each one and prompt for the new filename.

#cs
vi:ts=4 sw=4:
Ejoc
#ce
#include <GUIConstants.au3>
Opt("MustDeclareVars",1)

Global $bCopy   = 1;1 = Copy the file, 0 = Rename the file

Global $hGUI,$hPic,$hBrowse,$hQuit,$hLabel,$hCopy
Global $msg,$szFiles,$array,$szDir,$szFileName,$i,$szNewFileName
Global $GUIWidth    = Int(@DesktopWidth*.75)
Global $GUIHeight   = Int(@DesktopHeight*.75)

$hGUI       = GUICreate("JPEG Renamer",$GUIWidth,$GUIHeight)
$hPic       = GUICtrlCreatePic(@Systemdir & "\oobe\images\newmark1.jpg",0,0,$GUIWidth,$GUIHeight-45)
$hBrowse    = GUICtrlCreateButton("Browse",Int($GUIWidth/2)-50,$GUIHeight-40,45)
$hQuit      = GUICtrlCreateButton("Quit",Int($GUIWidth/2)+50,$GUIHeight-40,45)
$hLabel     = GUICtrlCreateLabel("Ready",1,$GUIHeight-13,$GUIWidth-2)
$hCopy      = GUICtrlCreateCheckBox("Copy the file instead of renaming",2,$GUIHeight-40)
GUICtrlSetState($hCopy,$GUI_CHECKED)

GUISetState()

While 1
    $msg    = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $hQuit Then ExitLoop
    If $msg = $hCopy Then
        If GUICtrlRead($hCopy) = $GUI_CHECKED Then $bCopy = 1
        If GUICtrlRead($hCopy) = $GUI_UNCHECKED Then $bCopy = 0
    EndIf
    If $msg = $hBrowse Then
        $szFiles    = FileOpenDialog("Select Files","","JPEGs (*.jpg;*.jpeg)",1+4)
        If Not @error And (StringInStr($szFiles,".jpg") OR StringInStr($szFiles,"*.jpeg")) Then
            $array  = StringSplit($szFiles,"|")
            If $array[0] = 1 Then; 1 file selected
                $array  = StringReplace($array[1],StringInStr($array[1],"\",0,-1),"|",-1)
                $array  = StringSplit($array,"|")
            EndIf

            $szDir  = $array[1]
            For $i = 2 To $array[0]
                $szFileName = $szDir & "\" & $array[$i]
                GUICtrlSetData($hLabel,"Loading")
                GUICtrlSetImage($hPic,$szFileName)
                GUICtrlSetData($hLabel,$szFileName)
                $szNewFileName  = FileSaveDialog("Save File",$szDir,"JPEGs (*.jpg;*.jpeg)")
                If Not @Error Then
                    If Not StringInStr($szNewFileName,".jpg") And Not StringInStr($szNewFileName,".jpeg") Then $szNewFileName &= ".jpg"
                    If FileExists($szNewFileName) Then
                        Dim $overwrite = MsgBox(1,"File Exists","OverWrite " & $szNewFileName & "?")
                        If $overwrite = 1 Then
                            If $bCopy Then
                                FileCopy($szFileName,$szNewFileName,1)
                            Else
                                FileMove($szFileName,$szNewFileName,1)
                            EndIf
                        EndIf
                    Else
                        If $bCopy Then
                            FileCopy($szFileName,$szNewFileName,1)
                        Else
                            FileMove($szFileName,$szNewFileName,1)
                        EndIf
                    EndIf
                EndIf
            Next
            MsgBox(0,"Finished",($array[0] - 1) & " Files processed")
            GUICtrlSetData($hLabel,($array[0] - 1) & " Files processed")
        EndIf
    EndIf
WEnd
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
Share on other sites

Thanks Ejoc. I have a mini camcorder and I hate having to rename the files sometimes... Umm... Except I lost my charger so I have to go buy a new one when I get some time :(

Thanks !

FootbaG
Link to comment
Share on other sites

Great program....... I take hundreds of pictures every week, some times more than 100 in a day.

two small things or ideas easy to fix

1. maybe a slight sleep so that i can see the pic for a sec before the "save as" window pops-up

2. i couldnt get the "save as" screen to close/quit (out of my face) without closing the program

great idea......... thanks

NEWHeader1.png

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...