snowman533 Posted February 20, 2010 Share Posted February 20, 2010 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 -Snowman533 File sorter.exe Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
JohnOne Posted February 20, 2010 Share Posted February 20, 2010 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 More sharing options...
dani Posted February 20, 2010 Share Posted February 20, 2010 (edited) Since you coded it in the first place, isn't it the easiest to do it yourself again ? 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 February 20, 2010 by d4ni Link to comment Share on other sites More sharing options...
snowman533 Posted February 20, 2010 Author Share Posted February 20, 2010 also ive forgotten how to make GUI's can someone help me plz? Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
JRowe Posted February 20, 2010 Share Posted February 20, 2010 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. [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
snowman533 Posted February 20, 2010 Author Share Posted February 20, 2010 (edited) #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 February 21, 2010 by snowman533 Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
Bowmore Posted February 21, 2010 Share Posted February 21, 2010 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 More sharing options...
snowman533 Posted February 21, 2010 Author Share Posted February 21, 2010 (edited) how do i make a text box its not in help... edit: i dont want a label Edited February 21, 2010 by snowman533 Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
JRowe Posted February 21, 2010 Share Posted February 21, 2010 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. [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
snowman533 Posted February 21, 2010 Author Share Posted February 21, 2010 (edited) nvm i got it to work using guictrlcreateinput and guictrlread now i have another problem expandcollapse popup#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 February 21, 2010 by snowman533 Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
snowman533 Posted February 21, 2010 Author Share Posted February 21, 2010 bump, i really cant figure out why im getting the error error: "Case" statement with no matching "Select" or "Switch" statement Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
JRowe Posted February 21, 2010 Share Posted February 21, 2010 (edited) AutoIt 1-2-3Search. Edited February 21, 2010 by JRowe [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
MvGulik Posted February 21, 2010 Share Posted February 21, 2010 (edited) 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 February 21, 2010 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 More sharing options...
snowman533 Posted February 21, 2010 Author Share Posted February 21, 2010 (edited) 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 expandcollapse popup#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 February 21, 2010 by snowman533 Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
dani Posted February 21, 2010 Share Posted February 21, 2010 (edited) 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 ): expandcollapse popup#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 February 21, 2010 by d4ni Link to comment Share on other sites More sharing options...
whim Posted February 21, 2010 Share Posted February 21, 2010 I'm still wondering why OP didn't mention the program's creation thread ...whim Link to comment Share on other sites More sharing options...
dani Posted February 21, 2010 Share Posted February 21, 2010 Wouldn't really have mattered as it only contains the .exe and not the original source Link to comment Share on other sites More sharing options...
snowman533 Posted February 21, 2010 Author Share Posted February 21, 2010 (edited) 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? expandcollapse popup#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 February 21, 2010 by snowman533 Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
dani Posted February 21, 2010 Share Posted February 21, 2010 (edited) 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: expandcollapse popup#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 February 21, 2010 by d4ni Link to comment Share on other sites More sharing options...
snowman533 Posted February 27, 2010 Author Share Posted February 27, 2010 (edited) <deleted this post, figured out the problem> Edited February 27, 2010 by snowman533 Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
Recommended Posts