Sign in to follow this  
Followers 0
John-Paul

Menu List Files

17 posts in this topic

#1 ·  Posted (edited)

I want to start a script and upon starting I want it to check for files (*.XLS, or CSV) in the current directory.

If if finds any I want it to then list these in a menu item.

I have so far the the very very basic steps..., this is only snippet

CODE

$GUI_CSVsMenu = GUICtrlCreateMenu ("&CSV Files")

$GUI_CSVCheck = GUICtrlCreateMenuitem ("List" ,$GUI_CSVsMenu)

CODE

GUICtrlSetState($GUI_CSVCheck, GUI_DISABLE)

Like i said its only in the idea stage.

I wonder if anyone has already done this before or can help in getting this to a working solution. Once in the menu the user need only select any one of the listed files and it is opened in the script/app.

jp

Edited by John-Paul

Share this post


Link to post
Share on other sites



hope it helps

#include <GuiConstants.au3>

Local $aFList = '', $sFiles, $hXls = FileFindFirstFile('*')
While 1
   $sFiles = FileFindNextFile($hXls)
   If @error Then
      FileClose($hXls)
      ExitLoop
   EndIf
   
   $aFList = $aFList & @LF & $sFiles
WEnd
$aFList = StringTrimLeft($aFList, 1)
$aFList = StringSplit($aFList, @LF)

GUICreate("MyGUI", 300, 300)
Local $ctrlFileMenu = GUICtrlCreateMenu('Files')

For $c = 1 To $aFList[0]
   $aFList[$c] = GUICtrlCreateMenuItem($aFList[$c], $ctrlFileMenu)
Next

GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case Else
        ;
   EndSelect
WEnd

Share this post


Link to post
Share on other sites

hope it helps

#include <GuiConstants.au3>

Local $aFList = '', $sFiles, $hXls = FileFindFirstFile('*')
While 1
   $sFiles = FileFindNextFile($hXls)
   If @error Then
      FileClose($hXls)
      ExitLoop
   EndIf
   
   $aFList = $aFList & @LF & $sFiles
WEnd
$aFList = StringTrimLeft($aFList, 1)
$aFList = StringSplit($aFList, @LF)

GUICreate("MyGUI", 300, 300)
Local $ctrlFileMenu = GUICtrlCreateMenu('Files')

For $c = 1 To $aFList[0]
   $aFList[$c] = GUICtrlCreateMenuItem($aFList[$c], $ctrlFileMenu)
Next

GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case Else
        ;
   EndSelect
WEnd

<{POST_SNAPBACK}>

This is exactly the bee's knee's.

Thank you.

jp

Share this post


Link to post
Share on other sites

hope it helps

For $c = 1 To $aFList[0]
   $aFList[$c] = GUICtrlCreateMenuItem($aFList[$c], $ctrlFileMenu)
Next

GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case Else
        ;
   EndSelect
WEnd

<{POST_SNAPBACK}>

Not to be ungrateful can I seek your input into how to get it to select a listed file.

The script is first class and works wonders, however when I get to the Case

select I'm lost.

CODE

Case $GUI_Msg = $GUI_CSVsMenu

or as you used

GUICtrlCreateMenuItem($aFList[$c], $ctrlFileMenu)

I am completely lost, tried several versions of code I found in the forum but nothing picks up the listed files.

There is a function called DoFileOpen($string) which will handle opening the selected file.

I must also admit that I can't seem to get my head around arrays and so when I see 'For $c = 1 To $aFList[0]' I'm off with the ferries.

Hope you can help.

jp

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

editing

Edited by HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites

editing

<{POST_SNAPBACK}>

Not sure what you mean, did I miss something.

Share this post


Link to post
Share on other sites

Hi, I'm trying to do the same and have got so far, but cannot get a response out of the goddam menu list.... arrghhh

have u had any success with this?? If not can anyone out there help me pls!

AutoIT rocks!!

cheers

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

In main loop add this:

GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case Else
        For $c = 1 To $aFList[0]
            If $msg = $aFList[$c] Then 
                $menuitem = GUICtrlRead($aFList[$c],1)
                MsgBox(0, "Name of selected file", $menuitem[0])
                ExitLoop
            EndIf
        Next
   EndSelect
WEnd

And I recommend to call _ArraySort before showing menu:

$aFList = StringSplit($aFList, @LF)
_ArraySort($aFList,0,1); first position (number of items) must stay there

Edit:

I was adding:

- code to _ArraySort

- ExitLoop after MsgBox()

Edited by Zedna

Share this post


Link to post
Share on other sites

In main loop add this:

GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case Else
        For $c = 1 To $aFList[0]
            If $msg = $aFList[$c] Then 
                $menuitem = GUICtrlRead($aFList[$c],1)
                MsgBox(0, "Name of selected file", $menuitem[0])
            EndIf
        Next
   EndSelect
WEnd

And I recommend to call _ArraySort before showing menu

<{POST_SNAPBACK}>

Thank you Zedna.

Works perfectly and completes the whole process orginally provided by Ezzetabi and it now gives others a complete solution to use if they wish.

As a thought to the forum, maybe a reference library with completed functional code could be a possibility for the future. I know its a job to manage such a resource so only a passing comment.

The journey is also part of our growth and so we all have to crawl before we walk and I don't mean to take that away from anyone.

Thanks.

jp

Share this post


Link to post
Share on other sites

Thanks also, however i am have a few problems probably because i have oneventmode set to 1, so i am getting error messages regarding the GUICtrlRead($aFList[$c],1) saying that i have too may parameters and then again with the MsgBox....($menuitem[0]) part (something about a subscript on a nonarray variable).. Any further help would be very much appreciated as this is the first script I have written.

many thanks

Honor

Share this post


Link to post
Share on other sites

Thanks also, however i am have a few problems probably because i have oneventmode set to 1, so i am getting error messages regarding the GUICtrlRead($aFList[$c],1) saying that i have too may parameters and then again with the MsgBox....($menuitem[0]) part (something about a subscript on a nonarray variable).. Any further help would be very much appreciated as this is the first script I have written.

many thanks

Honor

<{POST_SNAPBACK}>

Just tested this and works perfectly, hope it helps.

CODE

#include <GuiConstants.au3>

#include <Array.au3> ; Note to add this

Local $aFList = '', $sFiles, $hXls = FileFindFirstFile('*') ; change to whatever you want could be *.xls or *.csv

While 1

$sFiles = FileFindNextFile($hXls)

If @error Then

FileClose($hXls)

ExitLoop

EndIf

$aFList = $aFList & @LF & $sFiles

WEnd

$aFList = StringTrimLeft($aFList, 1)

$aFList = StringSplit($aFList, @LF)

GUICreate("MyGUI", 300, 300)

Local $ctrlFileMenu = GUICtrlCreateMenu('Files')

For $c = 1 To $aFList[0]

$aFList[$c] = GUICtrlCreateMenuItem($aFList[$c], $ctrlFileMenu)

Next

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case Else

For $c = 1 To $aFList[0]

If $msg = $aFList[$c] Then

$menuitem = GUICtrlRead($aFList[$c],1)

MsgBox(0, "Name of selected file", $menuitem[0])

ExitLoop

EndIf

Next

EndSelect

WEnd

Watch for text wrap.

jp

Share this post


Link to post
Share on other sites

Thanks also, however i am have a few problems probably because i have oneventmode set to 1, so i am getting error messages regarding the GUICtrlRead($aFList[$c],1) saying that i have too may parameters and then again with the MsgBox....($menuitem[0]) part (something about a subscript on a nonarray variable).. Any further help would be very much appreciated as this is the first script I have written.

many thanks

Honor

<{POST_SNAPBACK}>

You must use most recently beta version of AutoIt.

Share this post


Link to post
Share on other sites

Just tested this and works perfectly, hope it helps.

CODE

#include <GuiConstants.au3>

#include <Array.au3>  ; Note to add this

Local $aFList = '', $sFiles, $hXls = FileFindFirstFile('*') ; change to whatever you want could be *.xls or *.csv

While 1

  $sFiles = FileFindNextFile($hXls)

  If @error Then

      FileClose($hXls)

      ExitLoop

  EndIf

 

  $aFList = $aFList & @LF & $sFiles

WEnd

$aFList = StringTrimLeft($aFList, 1)

$aFList = StringSplit($aFList, @LF)

GUICreate("MyGUI", 300, 300)

Local $ctrlFileMenu = GUICtrlCreateMenu('Files')

For $c = 1 To $aFList[0]

  $aFList[$c] = GUICtrlCreateMenuItem($aFList[$c], $ctrlFileMenu)

Next

GUISetState()

While 1

  $msg = GUIGetMsg()

  Select

      Case $msg = $GUI_EVENT_CLOSE

        ExitLoop

      Case Else

        For $c = 1 To $aFList[0]

            If $msg = $aFList[$c] Then

                $menuitem = GUICtrlRead($aFList[$c],1)

                MsgBox(0, "Name of selected file", $menuitem[0])

                ExitLoop

            EndIf

        Next

  EndSelect

WEnd

Watch for text wrap.

jp

<{POST_SNAPBACK}>

Just add this and it will be done all:

$aFList = StringSplit($aFList, @LF)
_ArraySort($aFList,0,1); first position (number of items) must stay there

Share this post


Link to post
Share on other sites

Hi Zedna, ta again, by beta i presume you mean autoit-v3.1.1.55-bet.??

cheers

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Hi Zedna, ta again, by beta i presume you mean  autoit-v3.1.1.55-bet.??

cheers

<{POST_SNAPBACK}>

Not sure what version you have but Zedna's tweak works with v3.1.1.50 beta, have not tried ...55 yet.

Edited: Here's the sample file that works with v3.1.1.50 beta

_MenuListFiles.au3

Edited by John-Paul

Share this post


Link to post
Share on other sites

Hi JP, thanks, most of the code works fine with what i've got, its just the parts with the array variables, so i'll play around tonight and see if i can work it... I've also got to tweak it a little to go with the oneventmode being set to 1... anyway i'll also download the same version you have...

cheers

honor

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