Sign in to follow this  
Followers 0
snowman533

[solved] Need help with code

15 posts in this topic

#1 ·  Posted (edited)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
filesortgui()

Func filesortgui()
    $mnum = 0
    #Region ### START Koda GUI section ### Form=
    $Form1_1 = GUICreate("File Sorter v2.6", 625, 175, 283, 233)
    $MenuItem1 = GUICtrlCreateMenu("&File")
    $MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
    $MenuItem2 = GUICtrlCreateMenu("&Help")
    $MenuItem4 = GUICtrlCreateMenuItem("Online Documentation", $MenuItem2)
    $Input1 = GUICtrlCreateInput("Extension", 8, 16, 161, 21)
    $Input2 = GUICtrlCreateInput("Directory...Click Browse", 8, 64, 161, 21)
    $Button1 = GUICtrlCreateButton("Sort", 184, 8, 145, 33, $WS_GROUP)
    $Button2 = GUICtrlCreateButton("Browse", 184, 56, 145, 33, $WS_GROUP)
    $Button3 = GUICtrlCreateButton("Sort Dir", 336, 56, 137, 33, $WS_GROUP)
    $Button4 = GUICtrlCreateButton("SortALL", 336, 8, 137, 33, $WS_GROUP)
    $Button5 = GUICtrlCreateButton("Dir SortALL", 480, 56, 137, 33, $WS_GROUP)
    $Button6 = GUICtrlCreateButton("Add Default Dir", 8, 104, 137, 33, $WS_GROUP)
    $Combo1 = GUICtrlCreateCombo("Select a saved Default Dir here...", 144, 112, 473, 25)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button1
                $extension = GUICtrlRead($Input1)
                $path = @WorkingDir & "\Sorted\" & $extension
                If DirGetSize($path) = -1 Then DirCreate($path)
                $hSearch = FileFindFirstFile("*." & $extension)
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        FileMove($file, $path & "\" & $file)
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                FileClose($hSearch)
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
            Case $msg = $Button4
                $hSearch = FileFindFirstFile("*.*") ; Get a file handle
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        $extension = StringRegExpReplace($file, "(.*)\.(.*)", "\2")
                        $path = @WorkingDir & "\Sorted\" & $extension
                        If DirGetSize($path) = -1 Then DirCreate($path)
                        FileMove($file, $path & "\" & $file)
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
                FileClose($hSearch)
            Case $msg = $Button2
                $dir = FileSelectFolder("sort files in where?", @DesktopDir)
                GUICtrlSetData($Input2, $dir)
            Case $msg = $Button3
                $path = GUICtrlRead($Input2)
                $extension = GUICtrlRead($Input1)
                ;MsgBox(0, "test", $path & " " & $extension)
                If DirGetSize($path & "\Sorted\" & $extension) = -1 Then DirCreate($path & "\Sorted\" & $extension)
                $hSearch = FileFindFirstFile($path & "\*." & $extension)
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        FileMove($path & "\" & $file, $path & "\Sorted\" & $extension & "\" & $file)
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                FileClose($hSearch)
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
            Case $msg = $MenuItem3
                Exit
            Case $msg = $Button5
                $pget = GUICtrlRead($Input2)
                $hSearch = FileFindFirstFile($pget & "\*.*") ; Get a file handle
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        $extension = StringRegExpReplace($file, "(.*)\.(.*)", "\2")
                        $path = $pget & "\Sorted\" & $extension
                        If DirGetSize($path) = -1 Then DirCreate($path)
                        FileMove($file, $path & "\Sorted\" & $extension & "\" & $file)
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
                FileClose($hSearch)
        EndSelect
    WEnd
EndFunc   ;==>filesortgui

hello guys, for some reason Dir Sortall is only making the folders for the files found

Dir SortALL is button 5

what its supposed to do is, sort all files found in a selected directory into Sorted\<extension name>

at the moment its only making the folders for the extension names but nothing is being moved all the files stay where they are in that directory

what am i missing?

everything else works fine, Add default dir and select dir are not added as of yet

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites



snowman533,

If you do a bit of debugging, you will find that the FileMove command is returning 0 = failure. This is no doubt because the file is still held open by the FileFindNextFile command.

Why not use _FileListToArray to list the files instead? Then you get all the files in the folder into an array and you can do as you wish with the filenames without the same problem arising. :mellow:

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

M23 does _FileListToArray also include sub dirs? if it does then i need something that doesnt do subdirs

also why does Sort Dir work perfect as its using similair code?


Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

snowman533,

_FileListToArray does not look in subfolders.

As to your second point - I have no idea as I only looked at the code you said was not working. :lol: I will take a closer look now.

M23

Edit: I am an idiot! :mellow: And so are you! :( You were getting the paths incorrect in the FileMove function. You use different variable names for the source and dest paths in the 2 cases - that is where the confusion arose. This should work now:

Case $msg = $Button5
    $pget = GUICtrlRead($Input2)
    $hSearch = FileFindFirstFile($pget & "\*.*") ; Get a file handle
    $file = FileFindNextFile($hSearch)
    While Not @error
        If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
            $extension = StringRegExpReplace($file, "(.*)\.(.*)", "\2")
            $path = $pget & "\Sorted\" & $extension
            If DirGetSize($path) = -1 Then DirCreate($path)
            FileMove($pget & "\" & $file, $path & "\" & $file) ; <<<<<<<<<<<<<<< compare this to what you had!
            $mnum += 1
        EndIf
        $file = FileFindNextFile($hSearch)
     WEnd
     MsgBox(1, "Files moved", $mnum & " files have been moved")
     $mnum = 0
     FileClose($hSearch)

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

#5 ·  Posted (edited)

thanks so much M23, yes i am an idiot lol :mellow:

still learning :(

Edit: getting tidyup errors:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
filesortgui()

Func filesortgui()
    $mnum = 0
    #Region ### START Koda GUI section ### Form=
    $Form1_1 = GUICreate("File Sorter v2.6", 625, 175, 283, 233)
    $MenuItem1 = GUICtrlCreateMenu("&File")
    $MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
    $MenuItem2 = GUICtrlCreateMenu("&Help")
    $MenuItem4 = GUICtrlCreateMenuItem("Online Documentation", $MenuItem2)
    $Input1 = GUICtrlCreateInput("Extension", 8, 16, 161, 21)
    $Input2 = GUICtrlCreateInput("Directory...Click Browse", 8, 64, 161, 21)
    $Button1 = GUICtrlCreateButton("Sort", 184, 8, 145, 33, $WS_GROUP)
    $Button2 = GUICtrlCreateButton("Browse", 184, 56, 145, 33, $WS_GROUP)
    $Button3 = GUICtrlCreateButton("Sort Dir", 336, 56, 137, 33, $WS_GROUP)
    $Button4 = GUICtrlCreateButton("SortALL", 336, 8, 137, 33, $WS_GROUP)
    $Button5 = GUICtrlCreateButton("Dir SortALL", 480, 56, 137, 33, $WS_GROUP)
    $Button6 = GUICtrlCreateButton("Add Default Dir", 8, 104, 137, 33, $WS_GROUP)
    $Combo1 = GUICtrlCreateCombo("Select a saved Default Dir here...", 144, 112, 473, 25)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button1
                $extension = GUICtrlRead($Input1)
                $path = @WorkingDir & "\Sorted\" & $extension
                If DirGetSize($path) = -1 Then DirCreate($path)
                $hSearch = FileFindFirstFile("*." & $extension)
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        FileMove($file, $path & "\" & $file)
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                FileClose($hSearch)
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
            Case $msg = $Button4
                $hSearch = FileFindFirstFile("*.*") ; Get a file handle
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        $extension = StringRegExpReplace($file, "(.*)\.(.*)", "\2")
                        $path = @WorkingDir & "\Sorted\" & $extension
                        If DirGetSize($path) = -1 Then DirCreate($path)
                        FileMove($file, $path & "\" & $file)
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
                FileClose($hSearch)
            Case $msg = $Button2
                $dir = FileSelectFolder("sort files in where?", @DesktopDir)
                GUICtrlSetData($Input2, $dir)
            Case $msg = $Button3
                $path = GUICtrlRead($Input2)
                $extension = GUICtrlRead($Input1)
                ;MsgBox(0, "test", $path & " " & $extension)
                If DirGetSize($path & "\Sorted\" & $extension) = -1 Then DirCreate($path & "\Sorted\" & $extension)
                $hSearch = FileFindFirstFile($path & "\*." & $extension)
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        FileMove($path & "\" & $file, $path & "\Sorted\" & $extension & "\" & $file)
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                FileClose($hSearch)
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
            Case $msg = $MenuItem3
                Exit
            Case $msg = $Button5
                $pget = GUICtrlRead($Input2)
                $hSearch = FileFindFirstFile($pget & "\*.*") ; Get a file handle
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        $extension = StringRegExpReplace($file, "(.*)\.(.*)", "\2")
                        $path = $pget & "\Sorted\" & $extension
                        If DirGetSize($path) = -1 Then DirCreate($path)
                        FileMove($pget & "\" & $file, $path & "\" & $file) ; <<<<<<<<<<<<<<< compare this to what you had!
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
                FileClose($hSearch)
;### Tidy Error -> "wend" is closing previous "case" on line 29
            WEnd
;### Tidy Error -> "endfunc" is closing previous "select" on line 28
        EndFunc   ;==>filesortgui
;### Tidy Error -> while is never closed in your script.
;### Tidy Error -> while is never closed in your script.

i dont get it

edit2: nvm figured it out, was missing endselect above Wend on second last line

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

ok i have a new problem

this code is set to a button

$path=GUICtrlRead($Input2)
                If DirGetSize(@ScriptDir &"\Data") = -1 Then DirCreate(@ScriptDir &"\Data")
                $file=_WinAPI_CreateFile(@ScriptDir & "\Data\DD.txt", 3)
                FileWriteLine (@ScriptDir & "\Data\DD.txt", $path)
                FileClose(@ScriptDir & "\Data\DD.txt")

when i click the button it creates the Data Directory and DD.txt with no problems, but when i go to open DD.txt to se if its writing anything to it i get "windows cannot open this file because it is being accessed by another process" Unlocker says that it is being accessed by Autoit3.exe

but, the file (should be) closed so why is it still being accessed? what have i done wrong in the code?

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites

Does the same happen when you replace your _WinAPI_CreateFile call with:

$file = FileOpen(@ScriptDir & "\Data\DD.txt", 2)

I'm not sure how _WinAPI_CreateFile works but it doesn't seem needed here anyway :mellow:

Share this post


Link to post
Share on other sites

but, the file (should be) closed so why is it still being accessed? what have i done wrong in the code?

Why should it be closed? That's not how FileClose works, it need the file handle. See FileClose in the helpfile. And get rid of that _WinAPI_CreateFile, you seem to be using it the same way as FileOpen so stick to that.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

code:

$path = GUICtrlRead($Input2)

If DirGetSize(@ScriptDir & "\Data") = -1 Then DirCreate(@ScriptDir & "\Data")

$file = FileOpen(@ScriptDir & "\Data\DD.txt", 1)

FileWriteLine($file, $path & @CRLF)

$fcontents = _FileReadToArray($file, $Farray)

For $x = 1 to [!]$Farray[0]

GUICtrlSetData($Combo1,$Farray[$x])

Next

FileClose($file)

[!] = Error: Subscript Used with non array variable

trying to read the contents of the file to a combobox so when a new dir is selected so the combobox for default dirs is updated

what am i missing?

heres the full code if you need it:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Include <File.au3>
Dim $Farray
filesortgui()

Func filesortgui()
    $mnum = 0
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("File Sorter v2.8", 771, 164, 283, 233)
    $MenuItem1 = GUICtrlCreateMenu("&File")
    $MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
    $MenuItem2 = GUICtrlCreateMenu("&Help")
    $MenuItem4 = GUICtrlCreateMenuItem("Online Documentation", $MenuItem2)
    $Input1 = GUICtrlCreateInput("Extension", 8, 16, 161, 21)
    $Input2 = GUICtrlCreateInput("Directory...Click Browse", 8, 64, 161, 21)
    $Button1 = GUICtrlCreateButton("Sort", 184, 8, 145, 33, $WS_GROUP)
    $Button2 = GUICtrlCreateButton("Browse", 184, 56, 145, 33, $WS_GROUP)
    $Button3 = GUICtrlCreateButton("Sort Dir", 336, 56, 137, 33, $WS_GROUP)
    $Button4 = GUICtrlCreateButton("SortALL", 336, 8, 137, 33, $WS_GROUP)
    $Button5 = GUICtrlCreateButton("Dir SortALL", 480, 56, 137, 33, $WS_GROUP)
    $Button6 = GUICtrlCreateButton("Add Default Dir", 8, 104, 137, 33, $WS_GROUP)
    $Combo1 = GUICtrlCreateCombo("Select a saved Default Dir here...", 144, 112, 473, 25)
    $Input3 = GUICtrlCreateInput("File name contains?", 8, 40, 161, 21)
    $Button7 = GUICtrlCreateButton("Sort by FileName", 480, 8, 137, 33, $WS_GROUP)
    $Button8 = GUICtrlCreateButton("Dir Sort by FileName", 624, 56, 137, 33, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button1
                $extension = GUICtrlRead($Input1)
                $path = @WorkingDir & "\Sorted\" & $extension
                If DirGetSize($path) = -1 Then DirCreate($path)
                $hSearch = FileFindFirstFile("*." & $extension)
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        FileMove($file, $path & "\" & $file)
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                FileClose($hSearch)
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
            Case $msg = $Button4
                $hSearch = FileFindFirstFile("*.*") ; Get a file handle
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        $extension = StringRegExpReplace($file, "(.*)\.(.*)", "\2")
                        $path = @WorkingDir & "\Sorted\" & $extension
                        If DirGetSize($path) = -1 Then DirCreate($path)
                        FileMove($file, $path & "\" & $file)
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
                FileClose($hSearch)
            Case $msg = $Button2
                $dir = FileSelectFolder("sort files in where?", @DesktopDir, 2)
                GUICtrlSetData($Input2, $dir)
            Case $msg = $Button3
                $path = GUICtrlRead($Input2)
                $extension = GUICtrlRead($Input1)
                $fncontains = GUICtrlRead($Input3)
                ;MsgBox(0, "test", $path & " " & $extension)
                If DirGetSize($path & "\Sorted\" & $extension) = -1 Then DirCreate($path & "\Sorted\" & $extension)
                $hSearch = FileFindFirstFile($path & "\*." & $extension)
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        FileMove($path & "\" & $file, $path & "\Sorted\" & $extension & "\" & $file)
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                FileClose($hSearch)
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
            Case $msg = $MenuItem3
                Exit
            Case $msg = $Button5
                $pget = GUICtrlRead($Input2)
                $hSearch = FileFindFirstFile($pget & "\*.*") ; Get a file handle
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        $extension = StringRegExpReplace($file, "(.*)\.(.*)", "\2")
                        $path = $pget & "\Sorted\" & $extension
                        If DirGetSize($path) = -1 Then DirCreate($path)
                        FileMove($pget & "\" & $file, $path & "\" & $file) ; <<<<<<<<<<<<<<< compare this to what you had!
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
                FileClose($hSearch)
            Case $msg = $Button7
                $fncontains = GUICtrlRead($Input3)
                $path = @WorkingDir & "\Sorted\" & $fncontains
                If DirGetSize($path) = -1 Then DirCreate($path)
                $hSearch = FileFindFirstFile("*" & $fncontains & "*.*")
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        FileMove($file, $path & "\" & $file)
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                FileClose($hSearch)
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
            Case $msg = $Button8
                $pget = GUICtrlRead($Input2)
                $fncontains = GUICtrlRead($Input3)
                $hSearch = FileFindFirstFile($pget & "\*" & $fncontains & "*.*") ; Get a file handle
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not BitOR(@extended, $file = @ScriptName) Then ; Only for files -- and exclude the script itself
                        $extension = StringRegExpReplace($file, "(.*)\.(.*)", "\2")
                        $path = $pget & "\Sorted\" & $fncontains
                        If DirGetSize($path) = -1 Then DirCreate($path)
                        FileMove($pget & "\" & $file, $path & "\" & $file) ; <<<<<<<<<<<<<<< compare this to what you had!
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                MsgBox(1, "Files moved", $mm & " files have been moved")
                $mnum = 0
                FileClose($hSearch)
            Case $msg = $MenuItem4
                MsgBox(64, "Not Available", "Online Documentation currently unnavailable")
            Case $msg = $Button6
                $path = GUICtrlRead($Input2)
                If DirGetSize(@ScriptDir & "\Data") = -1 Then DirCreate(@ScriptDir & "\Data")
                $file = FileOpen(@ScriptDir & "\Data\DD.txt", 1)
                FileWriteLine($file, $path & @CRLF)
                $fcontents = _FileReadToArray($file, $Farray)
                For $x = 1 to $Farray[0]
                GUICtrlSetData($Combo1,$Farray[$x])
                Next
                FileClose($file)
        EndSelect
    WEnd
EndFunc   ;==>filesortgui

note: top section of code wouldnt let me highlight the code error locator i put in, the [!] in red so i had to put it in as normal text

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites

snowman533,

The error occurs because $Farray is not an array! :( 3 reasons why this is the case:

1. You might not have a file to read. You need a check to see if the DD.txt file exists - you create the Data folder if it does not exist, you also need to make sure the file within it exists.

2. You open the DD.txt file to write to it, but you do not close it before trying to read it into the array. The file is locked and so the _FileReadToArray command fails.

3. You use the file handle returned from the FileOpen command and not the file name for the _FileReadToArray command - check the correct syntax in the Help file.

So, when we remedy all of this, we get:

Case $msg = $Button6
                $path = GUICtrlRead($Input2)
                If DirGetSize(@ScriptDir & "\Data") = -1 Then DirCreate(@ScriptDir & "\Data")
                If Not FileExists(@ScriptDir & "\Data\DD.txt") Then FileWrite(@ScriptDir & "\Data\DD.txt", "") ; Ensure file exists <<<<<<<<<<<<<<<<<
                $file = FileOpen(@ScriptDir & "\Data\DD.txt", 1)
                FileWriteLine($file, $path & @CRLF)
                FileClose($file) ; Close it here ; <<<<<<<<<<<<<<<<<<<
                $fcontents = _FileReadToArray(@ScriptDir & "\Data\DD.txt", $Farray) ; Use name, not handle <<<<<<<<<<<<<<<<<<
                For $x = 1 to $Farray[0]
                GUICtrlSetData($Combo1,$Farray[$x])
                Next
                ;FileClose($file) ; And not here <<<<<<<<<<<<<<<<<<<<<<<<<<

and it all works nicely. But you might want to look at what exactly you are writing into your file if the user does not select a folder before pressing the button. :lol:

Top Tip: If you add some basic error checking into your code when you have problems, it helps you identify errors like this. :mellow:

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

#11 ·  Posted (edited)

Thanks M23

you are a massive help, now the next thing for me to figure out is the DLLCall

any ideas in particular to help me learn this extremely complicated part of the coding? (i need to use it for my next addition to the program)

i have DLLexplorer, but ive loaded it, taken one look at all the functions and im like (oohhh craaaaapp!!)

thanks again in advance

Edit: Also i have another easy question, how do i detect the default browser and launch a website using the detected browser?

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites

snowman533,

any ideas in particular to help me learn this extremely complicated part of the coding?

Yes - start a new topic! :( I am far from expert in that aspect of AutoIt - you will do far better getting someone who knows what they are talking about to help you there.

how do i detect the default browser and launch a website using the detected browser

That one I can answer (at least in part) :mellow: - ShellExecute($sURL) will open the relevant web page in the default browser.

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 M23 :lol:

the program is now ready for a full release, i just gotta write the documentation :mellow:

Thanks again, if i need any more help (non related to dllcall) ill pm you :(


Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites

snowman533

if i need any more help [...] ill pm you

Please do not send PMs asking for help - it is considered extremely rude here. If you do it to a Mod/Dev it is an almost certain ban. :(

Just post in the forum so everyone can see and learn - after all, that is why we are here in the first place. :mellow:

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