Jump to content

Create a scroll-able list of Checkboxes.


Nahuel
 Share

Recommended Posts

I made a script to rename all the files that a certain folder contains. It works fine with folders that don't have many files, because after you select the directory, it creates a list of checkboxes with the names of the files so you can select which ones to rename. If it has too many, the size of the GUI exceeds the desktop height.

I was thinking on making some sort of scrollable list or just organize them in columns, but I don't know how to do neither of those.

Here's my script.

#include <File.au3>
#include <Constants.au3>
#include <Guiconstants.au3>
#NoTrayIcon

Opt("GUIOnEventMode",1)
While 1
$Directorio=FileSelectFolder("",@HomePath) 
If @error=1 Then
    MsgBox(0,"Error","No folders selected")
    Exit
EndIf

$lista1=_FileListToArray($Directorio,"*.*",1)

If $lista1="" Then
    MsgBox(48,"Error","The selected directory is either not valid or it doesn't contain files.")
Else
    ExitLoop
EndIf
WEnd

$altolista=(25 * $lista1[0]+30)
$altoventana=$altolista+20
If $altoventana > @DesktopHeight Then
    MsgBox(0,"","Too many files in the selected directory!")
    Exit
EndIf

GUICreate("Files in "&$Directorio,350,$altoventana)
GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")
GUISetState()
GUICtrlCreateButton("Rename Files",125,$altoventana-35)
GUICtrlSetOnEvent(-1,"cambiar_nombre")  

obtenerArchivos()

Func _exit()
    Exit
EndFunc
Func obtenerArchivos()
$iCheckboxPos = 15
    Global $aCheckbox[UBound($lista1) ]
    For $i = 1 To $lista1[0] Step 1
        $aCheckbox[$i] = GUICtrlCreateCheckbox($lista1[$i], 10, $iCheckboxPos, -1, 20)
        GUICtrlSetState(-1, $GUI_CHECKED)
        $iCheckboxPos = $iCheckboxPos + 20
        $aCheckbox[0] = UBound($aCheckbox)
    Next
EndFunc

Func cambiar_nombre()
    $nuevonombre=InputBox("Change Name","Insert the new name")
    If $nuevonombre<>"" Then
    Dim $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(52,"Warning!","You are about to rename ALL the selected files in the chosen directory." & @CRLF & "Continue?")
    Select
       Case $iMsgBoxAnswer = 6 ;Yes
        $N=1
        For $i = 1 To (UBound($aCheckbox)-1)
            $sActiveCheckbox = $aCheckbox[$i]
            If GUICtrlRead($sActiveCheckbox) = $GUI_CHECKED Then
                $EXTENSION=StringRight($lista1[$i],4)
                $largo=StringLen($lista1[$i])
                $NOMBRE=(StringLeft($lista1[$i],$largo-4))
                $MoverError=FileMove($Directorio&"\"&$lista1[$i],$Directorio&"\"&$nuevonombre&"("&$N&")"&$EXTENSION)
                If $MoverError=0 Then
                    MsgBox(48,"Error","Could not be renamed: " &$lista1[$i]& @CRLF & "The file might be read-only, you don't have permission to rename it or the new name matches the old one.") 
                EndIf
                $N=$N+1
            EndIf
        Next
        MsgBox(64,"Files Renamed","Finished!")
        Exit
       Case $iMsgBoxAnswer = 7 ;No
       EndSelect
    EndIf

EndFunc

While 1
    Sleep(100)
WEnd
Link to comment
Share on other sites

Or you can search on forum for scrollable Gui :) - but personaly i didn't use it yet.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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