Sign in to follow this  
Followers 0
HardHackz

List Folder in Menu...

6 posts in this topic

Is it possible to make a menu that reads all the files in a certain folder? Such as the start menu does. Here is my script:

http://www.esnips.com/web/AutoIT-Scripts

It's the only one there, I want to add a menu that is called Desktop and has links to all the files/directories on the desktop.


[center]My BlogOldSock Programs (AutoIT Apps)A Message to Hackers! (NOT SKIDDIES!)OldSock Programs is my little "company."[/center]

Share this post


Link to post
Share on other sites



Perhaps you are looking for something like this:

;Quick example
;Note: parts of the code were taken from the helpfile

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("*.*");Note you could only search a specific filetype if needed
                                  ;Example: FileFindFirstFile("*.au3") <-- Finds .au3 files inside the directory

; Check if the search was unsuccessful
If $search = -1 Then ;If $search returns -1, it has failed to find any files
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) ;Find next existing file in the directory
    If @error Then ;Until the function fails, we continue to loop
        ExitLoop   ;If $file failed, meaning there are no more files left in the directory, we exit.
    Else           ;If the function succeeded then
        $readfile = FileRead($file) ;Read the text within the file
        MsgBox(0,"","The following are lines read from the file:" & @CRLF & $file & @CRLF & @CRLF & $readfile);Msgbox :)
    EndIf
WEnd

Basically reads each existing file in a directory, hope that helps.

Kurt


Awaiting Diablo III..

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ugh, FINE. Another excellent example:

#include <GUIConstants.au3>
#Include <GuiList.au3>

Local $data = ""

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("*.*");Note you could only search a specific filetype if needed
                                  ;Example: FileFindFirstFile("*.au3") <-- Finds .au3 files inside the directory

; Check if the search was unsuccessful
If $search = -1 Then ;If $search returns -1, it has failed to find any files
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) ;Find next existing file in the directory
    If @error Then ;Until the function fails, we continue to loop
        ExitLoop   ;If $file failed, meaning there are no more files left in the directory, we exit.
    Else           ;If the function succeeded then
        $readfile = FileRead($file) ;Read the text within the file
        $data     = $data & $file & "|"
    EndIf
WEnd

GUICreate("", 300, 450)
$List = GUICtrlCreateList("", 5, 5, 290, 390, BitOR($WS_BORDER, $WS_VSCROLL))
GUICtrlSetData(-1,$data)
$OK   = GUICtrlCreateButton("Read File", 5, 410, 290, 20)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $OK
            $index = _GUICtrlListGetCaretIndex($List)
            $path  = _GUICtrlListGetText($List, $index)
            $read  = FileRead($path)
            MsgBox(0,"",$read)
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

:whistle:

Kurt

EDIT: Minor correction in script

Edited by _Kurt

Awaiting Diablo III..

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

HardHackz

Hi,

Here is example of what i think you want to acomplish (It lists in to menu all links from desktop, and all shortcuts from favorites directory) :

Opt("GuiOnEventMode", 1)
Opt("RunErrorsFatal", 0)

$DesktopDir = @DesktopDir
$FavoritesDir = @FavoritesDir
$DirsArr = StringSplit($DesktopDir & "|" & $FavoritesDir, "|")


GUICreate("Files List In Menu Demo", 300, 200, 0, 0)
GUISetOnEvent(-3, "Quit")

$MainMenuID = GUICtrlCreateMenu("Files List")
$DesktopMenu = GUICtrlCreateMenu("Desktop", $MainMenuID)
$FavoritesMenu = GUICtrlCreateMenu("Favorites", $MainMenuID)

GUISetState()

;Searching for Desktop
$FindFirstFile = FileFindFirstFile($DesktopDir & "\*.lnk")
Do
    $NextFileSearch = FileFindNextFile($FindFirstFile)
    If @error Then ExitLoop
    GUICtrlCreateMenuitem($NextFileSearch, $DesktopMenu)
    GUICtrlSetOnEvent(-1, "DesktopMenuItem")
Until @error
FileClose($NextFileSearch)

;Searching for favorites
$FindFirstFile = FileFindFirstFile($FavoritesDir & "\*.url")
Do
    $NextFileSearch = FileFindNextFile($FindFirstFile)
    If @error Then ExitLoop
    GUICtrlCreateMenuitem($NextFileSearch, $FavoritesMenu)
    GUICtrlSetOnEvent(-1, "FavoritesMenuItem")
Until @error
FileClose($NextFileSearch)


While 1
    Sleep(100)
WEnd

Func Quit()
    Exit
EndFunc

Func DesktopMenuItem()
    $FileName = GUICtrlRead(@GUI_CtrlId, 1)
    ShellExecute($DesktopDir & "\" & $FileName)
EndFunc

Func FavoritesMenuItem()
    $FileName = GUICtrlRead(@GUI_CtrlId, 1)
    ShellExecute($FavoritesDir & "\" & $FileName)
EndFunc
Edited by MsCreatoR

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

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

Share this post


Link to post
Share on other sites

HardHackz

Hi,

Here is example of what i think you want to acomplish (It lists in to menu all links from desktop, and all shortcuts from favorites directory) :

Opt("GuiOnEventMode", 1)
Opt("RunErrorsFatal", 0)

$DesktopDir = @DesktopDir
$FavoritesDir = @FavoritesDir
$DirsArr = StringSplit($DesktopDir & "|" & $FavoritesDir, "|")
GUICreate("Files List In Menu Demo", 300, 200, 0, 0)
GUISetOnEvent(-3, "Quit")

$MainMenuID = GUICtrlCreateMenu("Files List")
$DesktopMenu = GUICtrlCreateMenu("Desktop", $MainMenuID)
$FavoritesMenu = GUICtrlCreateMenu("Favorites", $MainMenuID)

GUISetState()

;Searching for Desktop
$FindFirstFile = FileFindFirstFile($DesktopDir & "\*.lnk")
Do
    $NextFileSearch = FileFindNextFile($FindFirstFile)
    If @error Then ExitLoop
    GUICtrlCreateMenuitem($NextFileSearch, $DesktopMenu)
    GUICtrlSetOnEvent(-1, "DesktopMenuItem")
Until @error
FileClose($NextFileSearch)

;Searching for favorites
$FindFirstFile = FileFindFirstFile($FavoritesDir & "\*.url")
Do
    $NextFileSearch = FileFindNextFile($FindFirstFile)
    If @error Then ExitLoop
    GUICtrlCreateMenuitem($NextFileSearch, $FavoritesMenu)
    GUICtrlSetOnEvent(-1, "FavoritesMenuItem")
Until @error
FileClose($NextFileSearch)
While 1
    Sleep(100)
WEnd

Func Quit()
    Exit
EndFunc

Func DesktopMenuItem()
    $FileName = GUICtrlRead(@GUI_CtrlId, 1)
    ShellExecute($DesktopDir & "\" & $FileName)
EndFunc

Func FavoritesMenuItem()
    $FileName = GUICtrlRead(@GUI_CtrlId, 1)
    ShellExecute($FavoritesDir & "\" & $FileName)
EndFunc
Yea, but I'm not using GUI. I'm using menus from the taskbar icon.

[center]My BlogOldSock Programs (AutoIT Apps)A Message to Hackers! (NOT SKIDDIES!)OldSock Programs is my little "company."[/center]

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