Sign in to follow this  
Followers 0
lhk69

Get user to select files AND/OR folders, then "touch" them.

19 posts in this topic

Apologize right off the bat.  I am new and not very good at this. 

 

What I need is a script to present a GUI to get end users to be able select files and/or folders.  Then loop in those selections,  I assume put them in an array, and run a dos version of the UNIX "touch" command.  I need to be able to change the time and date of a selected bunch of files and folders full of files.

 

I have looked at scores of examples, UDF and other snippets.  I am not sure exactly sure how to use Melba's UDF.

 

Im just not sure exactly which direction to go.  I can’t even get a basic GUI to select files AND folders.

 

Please help me go in the right direction.  Once I can get the GUI to get my user to be able to select files AND folders, I can make array and act upon the items from there.

 

I could insert a bunch of attempts I’ve made here, but they are all already posted and examples I have used from posts.

  

ANY help would be appreciated.

Thank you.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

lhk69,

Trying to select files and folders at the same time from the same dialog is not possible in my opinion.  Certainly the FileOpenDialog and FileSelectFolder dialogs cannot be combined. :(

My ChooseFileFolder UDF will allow you to choose a selection of files from any folder on a path or any of the folders on that path - but not both together, so you would need 2 passes.  You could concatenate the 2 returned arrays and so action them in one loop - but I think you are stymied in getting selection of both at the same time. ;)

M23

Edit: And why use "touch" - you can change the time and date with "FileSetTime" in Autoit. ;)

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Ihk69,

You may be able to adapt this to your needs

; *** Start added by AutoIt3Wrapper ***
#include <WindowsConstants.au3>
; *** End added by AutoIt3Wrapper ***

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <array.au3>

#AutoIt3Wrapper_Add_Constants=n

local $gui010   =   guicreate('',900,600)
local $aSize    =   wingetclientsize($gui010)
                    guisetfont(8.5,600)
                    guictrlcreatelabel('Folder',            020,020,050,20)
local $inp010   =   guictrlcreateinput('',                  070,020,470,20)
local $btn010   =   guictrlcreatebutton('...',              560,020,20,20)
                    guictrlcreatelabel('Files Selected',    020,050,200,20)
local $edt010   =   guictrlcreateedit('',                   020,070,$asize[0]-40,200,bitor($es_readonly,$ws_vscroll,$ws_hscroll))
                    guictrlcreatelabel('Log',               020,290,200,20)
local $edt020   =   guictrlcreateedit('',                   020,310,$asize[0]-40,200,bitor($es_readonly,$ws_vscroll,$ws_hscroll))
local $btn020   =   guictrlcreatebutton('Do Something With The Files Listed',20,$asize[1]-30,$asize[0]-40,20)
                    guisetstate()

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $btn010
            guictrlsetdata($edt010,chk_folder(''))
        case $inp010
            guictrlsetdata($edt010,chk_folder(guictrlread($inp010)))
        case $btn020
            if stringlen(guictrlread($inp010)) = 0 then
                guictrlsetdata($edt010,chk_folder(guictrlread($inp010)))
            Else
                Process_Files(guictrlread($edt010))
            endif
    EndSwitch
WEnd


func chk_folder($str)

    if fileexists($str) = 0 then

        $folder = FileSelectFolder("Choose a folder.", $str)
        if @error = 1 then
            guictrlsetdata($edt020,'Folder Selection terminated' & @crlf,1)
            guictrlsetdata($inp010,'')
            guictrlsetstate($inp010,$gui_focus)
            Return ''
        endif

        guictrlsetdata($edt020,'Processing folder = ' & $folder & @crlf,1)
        guictrlsetdata($inp010,$folder)

    Else

        $folder = guictrlread($inp010)

    endif

    return get_files($folder)

endfunc

func get_files($str)

    if stringright($str,1) <> '\' then $str = $str & '\'

    local $files, $afiles
    $files = FileOpenDialog('Select Files',$str,'Text (*.txt))|ALL (*.*)',4)

    if stringinstr($files,'|') = 0 then
        $afiles = stringsplit($files,'\')
        return $afiles[ubound($afiles) - 1]
    else
        $afiles = stringsplit($files,'|')
        return _arraytostring($afiles,@crlf,2,ubound($afiles) - 1)
    endif

endfunc

func Process_Files($str)

    ; here's where you do your thing...

    $afiles = stringsplit($str,@crlf,1)

    for $1 = 1 to $afiles[0]

        ; I'm just displaying the files as they are found in the array...do whatever you want

        guictrlsetdata($edt020,'I just did something for file = ' & $afiles[$1] & @crlf,1)
    Next

endfunc

Note - This is just a demo for another topic so you'll want to customize some things and add more error checking.

           Files are listed in an edit control.  This can be easily chanded to a list/listview/combo for individual or group file selection. 

           As is, all files are read from the edit control when the "Do Something" button is actioned.

Good Luck,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Kylomas.

This is great.  I think I CAN get something going with this.  I really appreciate your input.  I thank you.

 

Melba.  I know you are right.  I’m sure it will take two passes. You are a genius.  If you say it cant be done the way I want to do it, then I’m sure it can’t.  But, with that said, I really do appreciate your input.  At least I’m not missing something stupid.

AND, Melba, I guess I didn’t see the time/date change function.  I will be using that instead.  Like I said, you are brilliant!!

 

I wonder how other applications achieve this function?  I mean, I’ve seen it.  Doesn’t something like winrar allow you select multiple files and folders in their GUI to add to an archive??

Anyway, thank you both very much.

Share this post


Link to post
Share on other sites

lhk69,

I am sure it can be done in one pass - but certainly no-one has yet done it in AutoIt. Let me have a think about how I might adapt the ChooseFileFolder UDF to do it - I like a challenge. :D

But it might take a while - so do not hold your breath. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks Melba.

I'll continue down the path that Kylomas set up for me.  With a few minor tweaks, its enough to get me going.

I anxiously await your solution, but PROMISE not to bug you. (heheh.  BUG, no pun intended)

Thanks again.

Share this post


Link to post
Share on other sites

lhk69,

It looks like it might be easier than I thought - I will try and get something out tomorrow after my round of golf. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

thank you.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

lhk69,

Here you go - try this Beta version: see new Beta below

And here is an example to show it working - the first instance allows you to select both files and folders, the second only files: :)

#include "ChooseFileFolder_Mod.au3"

Local $sRet, $aRet
Local $sRootFolder = StringRegExpReplace(@AutoItExe, "(^.*\\)(.*)", "\1")

; Register WM_NOTIFY handler
$sRet = _CFF_RegMsg()
If Not $sRet Then
    MsgBox(64, "Failure!", "Handler not registered")
    Exit
EndIf

$sRet = _CFF_Choose("Ex 4a: Select multiple folders and/or files", 300, 500, -1, -1, $sRootFolder, Default, 12 + 16, 20)
If $sRet Then
    $aRet = StringSplit($sRet, "|")
    $sRet = ""
    For $i = 1 To $aRet[0]
        $sRet &= $aRet[$i] & @CRLF
    Next
    MsgBox(64, "Ex 4a", "Selected:" & @CRLF & @CRLF & $sRet)
Else
    MsgBox(64, "Ex 4a", "No Selection")
EndIf

$sRet = _CFF_Choose("Ex 4b: Select multiple files only", 300, 500, -1, -1, $sRootFolder, Default, 12, 20)
If $sRet Then
    $aRet = StringSplit($sRet, "|")
    $sRet = ""
    For $i = 1 To $aRet[0]
        $sRet &= $aRet[$i] & @CRLF
    Next
    MsgBox(64, "Ex 4b", "Selected:" & @CRLF & @CRLF & $sRet)
Else
    MsgBox(64, "Ex 4b", "No Selection")
EndIf

I have set it up so that folders are returned with a trailing "" for easy identification - happy with that? :huh:

M23

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba.

This is totally awesome.  You really know what you are doing.  I am VERY impressed.  This is perfect.

Thank you very much.

Share this post


Link to post
Share on other sites

lhk69,

Glad I could help.  I will keep testing the changes for a while and then release a new version.  Thanks for the push to change it. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba.

Just curious.  How would YOU handle the implementation?  Selecting files AND/OR folders, then looping on those selections and do a FileSetTime on them.  First, Id put them in in an array, then loop each item in array and do a FileSetTime - including recursing chosen folders.   By the way, is there a way to remove ONE item after youve selected it?  AND, check to see if an item has already been added to prevent duplicates?

Again, I think you for all your efforts.

#cs ----------------------------------------------------------------------------
#include "ChooseFileFolder_Mod.au3"
#include <array.au3>

Local $sRet, $aRet
Local $files, $afiles
; Local $sRootFolder = StringRegExpReplace(@AutoItExe, "(^.*\\)(.*)", "\1")

Local $sRootFolder =  FileSelectFolder("Choose a folder.", "")

; Register WM_NOTIFY handler
$sRet = _CFF_RegMsg()
If Not $sRet Then
    MsgBox(64, "Failure!", "Handler not registered")
    Exit
EndIf

$sRet = _CFF_Choose("Program - Archive Tool - Select multiple folders and/or files.", 300, 500, -1, -1, $sRootFolder, Default, 12 + 16, 20)

If $sRet Then
    MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$sRet' & @lf & @lf & 'Return:' & @lf & $sRet) ;### Debug MSGBOX

    $aRet = StringSplit($sRet, "|")
    $sRet = ""

    For $i = 1 To $aRet[0]
        $sRet &= $aRet[$i] & @CRLF
    Next

    MsgBox(64, "Program", "Selected:" & @CRLF & @CRLF & $sRet)

    MakeArray($aRet)

    _ArrayDisplay($afiles)

Else

    MsgBox(64, "Program", "No Selection")

EndIf


Func MakeArray($sRet)

    If StringInStr($sRet, '|') = 0 Then

        $afiles = StringSplit($sRet, '\')
        Return $afiles[UBound($afiles) - 1]
    Else
        $afiles = StringSplit($sRet, '|')
        Return _ArrayToString($afiles, @CRLF, 2, UBound($afiles) - 1)
    EndIf

EndFunc

Share this post


Link to post
Share on other sites

lhk59,

No need for the Beta - look in the thread for the new release. :)

Answers to your questions:

- I would not do it very differently - although I would have used my UDF rather than FileGetFolder! :whistle:

 

- You can put the returned items into an array very easily using StringSplit - no need for your function. ;)

 

- There is no way at present to unselect an item after having selected it or prevent duplicates - I will take a look and see if I can do something along those lines. :sweating:

Glad you find the UDF useful. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

OH, by the way, I (of course) am now using your UDF rather than FileGetFolder.

Im still too dumb to realize what I have INCLUDED!!..

You are THE MAN.

Thank you.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

lhk69 (and any other readers),

I have amended the ChooseFileFolder UDF to allow (or not) multiple instances of selected items and also added the ability to delete previously selected items: see new Beta below

- Add 32 to the $iDisplay parameter to allow multiple instances of the same selection - default behaviour is to allow only a single instance.

- Press Ctrl while selecting an item to delete it from the list - if multiple instances exist then only the latest instance is deleted.

Happy to get feedback on performance and implementation of these new features before releasing a new version. :)

M23

Edited by Melba23
Beta code removed

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba.

Again.  A miracle.  This totally works.  Just as you describe.

It did NOT allow multiple selections of the same FILE OR FOLDER!! (Unless, of course I add 32)

And I was able to delete selections by using CTRL.

You are brilliant.  How did you get SO good at this???

Thank you!!

Share this post


Link to post
Share on other sites

lhk69,

Glad you like it.  Here is a streamlined version of that Beta for you to test:

It is the same basic code, but reorganised to make it easier for me to modify when you ask me to include the next enhancement! :P

And this is pretty basic stuff compared to what some people in this community can produce - but it does help that I have been coding in one form or another for around 45 years. :whistle:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Well, basic or not, the UDF you have written should be hard coded into the AutoIt code and become included.

I am VERY impressed, and once again,. thank you very much.  Over the next few days, I "MAY" see the need for changes, but I doubt it.  you have done WAY more for me than I could have ever expected.

If you are ever close to Pittsbugh, I owe you as many beers as you want!!

Lee

Share this post


Link to post
Share on other sites

lhk69,

Alas, I am some distance and a large ocean away - but I will gladly drink one with you if I ever get there. :)

Delighted I could help - and do feel free to ask for any further enhancements you might need. I do not guarantee to include them, but I am always open to suggestions. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0