Jump to content

Need code for old program


Recommended Posts

Hello guys, i need to extend on a program that i made

in my ignorance i lost the source code, its nowhere to be found, not even on any of my file hosts

and its been soo long since i last used autoit

i need someone to replicate the code

what it does is, in the directory that its in, and only in that directory (@workingdir) (subs arent affected, did have a system protection feature which protects program files and system files, that part of the code i can easily put back in)

it asks the user what extension to sort, then the user clicks sort and it scans the files for the selected extensions and moves them into Sorted/<extensionname>

why do i need the code? because i want to extend the program a bit, ill probably en up posting a topic with a problem knowing my luck

program is attached

all help appreciated

thanks guys :mellow:

-Snowman533

File sorter.exe

Intermediate AutoIt/Autohotkey User

Link to comment
Share on other sites

Not exactly sure what you are asking for, but it seems you want someone to run that .exe on their computer, look at what it does then write code for you that does the same.

If this is your code, then you are the ideal person to do it again.

Asking people to write code for you is considered lazy here .

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Since you coded it in the first place, isn't it the easiest to do it yourself again :mellow:? Besides, what you want is extremely easy so I assume you can do it yourself.

Just make a function with at its core something like:

$path = @WorkingDir & "\Sorted\" & $ext
If DirGetSize($path) = -1 Then DirCreate($path)
$hSearch = FileFindFirstFile("*." & $ext)
$file = FileFindNextFile($hSearch)
While Not @error
  If Not @extended Then ; Only for files (although I am not sure if any directories would match anyway as you have a wildcard of *.$ext
    FileMove($file, $path & "\" & $file)
    $file = FileFindNextFile($hSearch)
  EndIf
WEnd
FileClose($hSearch)

You could also leave the wildcard in FileFindFirstFile "*.*" and then use RegExp to check the extension, it's safer than this as I think using a *.txt wildcard would also match imaginary *.txtz files. With a RegExp you can specify ".*\.txt\z" to make sure it ends after .txt.

Edited by d4ni
Link to comment
Share on other sites

Learn to use the help file... it is the singularly most wonderful piece of assistance you could possibly be given, and its already on your computer. Click on your start menu, open the AutoIt v3 folder, and click the Help file. In there, everything is explained and detailed for you, in simple, easy to understand english.

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>

filesortgui()
Dim $ext

Func filesortgui()
    Local $msg
    GUICreate("File Sorter", 1000, 500)
    $button1 = GUICtrlCreateButton("Sort", 20, 20)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $button1
                $path = @WorkingDir & "\Sorted\" & $ext
                If DirGetSize($path) = -1 Then DirCreate($path)
                $hSearch = FileFindFirstFile("*." & $ext)
                $file = FileFindNextFile($hSearch)
                    While Not @error
                        If Not @extended Then ; Only for files (although I am not sure if any directories would match anyway as you have a wildcard of *.$ext
                FileMove($file, $path & "\" & $file)
            $file = FileFindNextFile($hSearch)
  EndIf
WEnd
FileClose($hSearch)
        EndSelect
    WEnd
EndFunc;==>docgui

Line 17 variable used without being declared = $ext

wtf i declared it on line 4

and how do i make a textbox? cant find it in help

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Link to comment
Share on other sites

When filesortgui() is called on line 3 $ext has not been declared,

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Text boxes are called something different. If you want to find something in the help file, it will be there. It's up to you to learn what things are properly called. In this case, what you're looking for is called an Edit control. GuiCtrlCreateEdit() is the function to create an Edit box.

Check out the AutoIt 1-2-3 tutorial before you go any farther. It will save you a headache and lots of frustration.

Link to comment
Share on other sites

nvm i got it to work using guictrlcreateinput and guictrlread

now i have another problem

#include <GUIConstantsEx.au3>

Dim $mnum, $mnum2
filesortgui()

Func filesortgui()
    Local $msg
    GUICreate("File Sorter", 1000, 500)
    $button1 = GUICtrlCreateButton("Sort", 20, 50)
    GUICtrlCreateInput ( "extension goes here", 20, 20, 200, 20)
    $button2 = GUICtrlCreateButton("SortALL", 20, 80)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $button1
                $path = @WorkingDir & "\Sorted\" & GUICtrlRead (4)
                If DirGetSize($path) = -1 Then DirCreate($path)
                $hSearch = FileFindFirstFile("*." & GUICtrlRead (4))
                $file = FileFindNextFile($hSearch)
                    While Not @error
                        If Not @extended Then ; Only for files (although I am not sure if any directories would match anyway as you have a wildcard of *.$ext
                $mnum += 1
                FileMove($file, $path & "\" & $file)
            $file = FileFindNextFile($hSearch)
            Case $msg = $button2
                $hSearch = FileFindFirstFile("*.*") ; gets next file name
                $hread=StringSplit ( $hSearch, ".") ; splits the filename
                $extget=StringRight ( $hread, 3 ) ;gets the extension name (3 chars)
                $path = @WorkingDir & "\Sorted\" & $extget ;creates a path for the extension
                If DirGetSize($path) = -1 Then DirCreate($path)
                $file = FileFindNextFile($hSearch)
                    While Not @error
                        If Not @extended Then
                $mnum += 1
                FileMove($file, $path & "\" & $file)
            $file = FileFindNextFile($hSearch)
        EndIf
WEnd
FileClose($hSearch)
MsgBox ( 1, "Files moved", $mnum & " files have been moved")
$mnum = 0
        EndSelect
    WEnd
EndFunc;==>docgui

case $msg = $button2

error: "Case" statement with no matching "Select" or "Switch" statement

Edit: Button1 works as intended, now i want it to sort all files it comes across in the dir with Button2

i found using an edit to be too flimsy as it wouldnt read it properly, soon as i changed it to an input it worked perfectly

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Link to comment
Share on other sites

Suggestion: Start by using/posting normal indentated code. (Or hit [CTRL+T] if your using Scite4AutoIt)

...\_TEST_.au3(72) : ### Tidy Error -> "endselect" is closing previous "while" on line 49

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Suggestion: Start by using/posting normal indentated code. (Or hit [CTRL+T] if your using Scite4AutoIt)

...\_TEST_.au3(72) : ### Tidy Error -> "endselect" is closing previous "while" on line 49

wow thanks, apparently i got erors all over the place, tx for the ctrl t hotkey

heres the tidied code

#include <GUIConstantsEx.au3>

Dim $mnum, $mnum2, $hSearch
filesortgui()

Func filesortgui()
    Local $msg
    GUICreate("File Sorter", 1000, 500)
    $button1 = GUICtrlCreateButton("Sort", 20, 50)
    GUICtrlCreateInput("extension goes here", 20, 20, 200, 20)
    $button2 = GUICtrlCreateButton("SortALL", 20, 80)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $button1
                $path = @WorkingDir & "\Sorted\" & GUICtrlRead(4)
                $hSearch = FileFindFirstFile("*.*") ; gets next file name
                $hread = StringSplit($hSearch, ".") ; splits the filename
                $extget = StringRight($hread, 3) ;gets the extension name (3 chars)
                $path = @WorkingDir & "\Sorted\" & $extget ;creates a path for the extension
                If DirGetSize($path) = -1 Then DirCreate($path)
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not @extended Then
                        $mnum += 1
                        FileMove($file, $path & "\" & $file)
                        $file = FileFindNextFile($hSearch)
                    EndIf
                WEnd
                Switch
                    Case $msg = $button2
                        If DirGetSize($path) = -1 Then DirCreate($path)
                        $hSearch = FileFindFirstFile("*." & GUICtrlRead(4))
                        $file = FileFindNextFile($hSearch)
                        While Not @error
                            If Not @extended Then ; Only for files (although I am not sure if any directories would match anyway as you have a wildcard of *.$ext
                                $mnum += 1
                                FileMove($file, $path & "\" & $file)
                                $file = FileFindNextFile($hSearch)
                            EndIf
                        WEnd
                EndSwitch
                ;EndIf
        EndSelect
        FileClose($hSearch)
        MsgBox(1, "Files moved", $mnum & " files have been moved")
        $mnum = 0
    WEnd
EndFunc   ;==>filesortgui

fixed the errors but for some reason, some part of the code is being executed before the buton for it is pressed

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Link to comment
Share on other sites

Well, it's good you used my code as core but you definitely didn't use it right :( So I decided to fix it. For one thing, you had the labels on the buttons the other way around, SortALL expected an extension in the inputbox, and Sort sorted everything, sigh. Also, for some reason you decided to nest a Switch containing $button2 within the button1 Case. It was unreachable. You also had the MsgBox('xx files moved') within the While 1 Loop at the end, so yes, that was executed before the button was pressed.

All in all it was horrible, and you really need to look more carefully at your own code. It is probably better to not ask for code anymore as you seem to only Copy-Paste it without looking what it actually does.

Well anyway, here you go it works now (I replaced FileMove with FileCopy just to be sure nothing will be messed up. Also, I think this is required, otherwise it tries to move the .au3 while it's running :mellow:):

#include <GUIConstantsEx.au3>

Dim $mnum, $mnum2, $hSearch
filesortgui()

Func filesortgui()
    Local $msg
    Local $mnum = 0
    GUICreate("File Sorter", 1000, 500)
    $button1 = GUICtrlCreateButton("SortALL", 20, 50)
    GUICtrlCreateInput("extension goes here", 20, 20, 200, 20)
    $button2 = GUICtrlCreateButton("Sort", 20, 80)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button1
            $hSearch = FileFindFirstFile("*.*") ; Get a file handle
            $file = FileFindNextFile($hSearch)
            While Not @error
                If Not @extended Then
                    $extension = StringRegExpReplace($file, "(.*)\.(.*)", "\2")
                    $path = @WorkingDir & "\Sorted\" & $extension
                    If DirGetSize($path) = -1 Then DirCreate($path)
                    FileCopy($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
            $extension = GUICtrlRead(4)
            $path = @WorkingDir & "\Sorted\" & $extension
            If DirGetSize($path) = -1 Then DirCreate($path)
            $hSearch = FileFindFirstFile("*." & $extension)
            $file = FileFindNextFile($hSearch)
            While Not @error
                If Not @extended Then ; Only for files (although I am not sure if any directories would match anyway as you have a wildcard of *.$ext
                    FileCopy($file, $path & "\" & $file)
                    $mnum += 1
                EndIf
                $file = FileFindNextFile($hSearch)
            WEnd
            FileClose($hSearch)
            MsgBox(1, "Files moved", $mnum & " files have been moved")
            $mnum = 0
        EndSelect
    WEnd
EndFunc   ;==>filesortgui
Edited by d4ni
Link to comment
Share on other sites

exactly, thats why i didnt refer to it

and tx d4ni now it works

would it be posible to change the filecopy back to filemove but add an exception for the name of the script?

i tried changing filecopy to filemove but its only copying still, why?

#include < GUIConstantsEx.au3 >

Dim $mnum, $mnum2, $hSearch
filesortgui()

Func filesortgui()
    Local $msg
    Local $mnum = 0
    GUICreate("File Sorter", 1000, 500)
    $button1 = GUICtrlCreateButton("SortALL", 20, 50)
    GUICtrlCreateInput("extension goes here", 20, 20, 200, 20)
    $button2 = GUICtrlCreateButton("Sort", 20, 80)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $button1
                $hSearch = FileFindFirstFile("*.*") ; Get a file handle
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not @extended Then
                        $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
                $extension = GUICtrlRead(4)
                $path = @WorkingDir & "\Sorted\" & $extension
                If DirGetSize($path) = -1 Then DirCreate($path)
                $hSearch = FileFindFirstFile("*." & $extension)
                $file = FileFindNextFile($hSearch)
                While Not @error
                    If Not @extended Then ; Only for files (although I am not sure if any directories would match anyway as you have a wildcard of *.$ext
                        FileMove($file, $path & "\" & $file)
                        $mnum += 1
                    EndIf
                    $file = FileFindNextFile($hSearch)
                WEnd
                FileClose($hSearch)
                MsgBox(1, "Files moved", $mnum & " files have been moved")
                $mnum = 0
        EndSelect
    WEnd
EndFunc   ;==>filesortgui
Edited by snowman533

Intermediate AutoIt/Autohotkey User

Link to comment
Share on other sites

Hi snowman,

I think you didn't change it properly (maybe in only one of the cases?), cause it works fine if I change it to FileMove. Actually, it seems to move the script as well, apparently the .au3 file is not in use when it's running. Anyway, to exclude the scriptfile from being moved, use this updated code:

#include <GUIConstantsEx.au3>

FileSortGUI()

Func FileSortGUI()
    $mnum = 0
    GUICreate("File Sorter", 200, 150)
    $button1 = GUICtrlCreateButton("SortALL", 20, 50)
    GUICtrlCreateInput("extension goes here", 20, 20, 200, 20)
    $button2 = GUICtrlCreateButton("Sort", 20, 80)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button1
            $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
            $extension = GUICtrlRead(4)
            $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
        EndSelect
    WEnd
EndFunc ; ==> FileSortGUI
Edited by d4ni
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...