NegativeNrG Posted March 10, 2006 Share Posted March 10, 2006 (edited) ok, i didn't need much help until now, i've been learning Functions about Files, but im stuck with the FileFindfirst/FileFindNext etc..Example:HotKeySet('{HOME}','_FindnextFile') While 1 Sleep(100) WEnd Func _FindNextFile() $FindFile = FileFindFirstFile('*.exe') $filetorun = FileFindNextFile($FindFile) Run($filetorun) FileClose($FindFile) EndFuncThis will Only Run 1 File, how would i make it Search for .exe randomly and run it?. Edited March 10, 2006 by NegativeNrG [size=20]My File Upload[/size]Register at my site and upload. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 10, 2006 Moderators Share Posted March 10, 2006 ok, i didn't need much help until now, i've been learning Functions about Files, but im stuck with the FileFindfirst/FileFindNext etc.. Example: HotKeySet('{HOME}','_FindnextFile') While 1 Sleep(100) WEnd Func _FindNextFile() $FindFile = FileFindFirstFile('*.exe') $filetorun = FileFindNextFile($FindFile) Run($filetorun) FileClose($FindFile) EndFunc This will Only Run 1 File, how would i make it Search for .exe randomly and run it?.With a loop... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
NegativeNrG Posted March 10, 2006 Author Share Posted March 10, 2006 (edited) yeh, but if i do that, it will actually run every file that is found, if its in a loop. although i want if the user press the HOME key, it would find a random File and execute it. Edited March 10, 2006 by NegativeNrG [size=20]My File Upload[/size]Register at my site and upload. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 10, 2006 Moderators Share Posted March 10, 2006 This is rather bulky, because to make sure you don't throw an error, I'm having to run through the directory twice... I'm not aware off the top of my head, of a command that instantly gives you how many files are in a directory (which would be better of course).HotKeySet('{HOME}','_FindnextFile') While 1 Sleep(100) WEnd Func _FindNextFile() Local $cCounter = 0 Local $FindFile = FileFindFirstFile('*.exe') While 1 $cCounter = $cCounter + 1 FileFindNextFile($FindFile) If @error Then ExitLoop WEnd FileClose($FindFile) $FindFile = FileFindFirstFile('*.exe') Local $RandomFile = Random(1, $cCounter, 1) For $i = 1 To $cCounter $filetorun = FileFindNextFile($FindFile) If @error Then ExitLoop If $RandomFile = $i Then Run($filetorun) ExitLoop EndIf Next FileClose($FindFile) EndFuncThis is untested.... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
NegativeNrG Posted March 10, 2006 Author Share Posted March 10, 2006 ok, i just tested it and successfully worked. Thanks alot Smokey. [size=20]My File Upload[/size]Register at my site and upload. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 10, 2006 Moderators Share Posted March 10, 2006 ok, i just tested it and successfully worked. Thanks alot Smokey.Thanks... After you replied, I looked at it, and it's really inefficient... so I thought I'd try again... This only goes through it 1 time, returns an Array, does the Random Option, and simply picks it out from the Array of exe'sGlobal $s_SearchDirectory = @ScriptDir Global $s_SearchExtension = '*.exe' HotKeySet('{HOME}','_FindnextFile') While 1 Sleep(100) WEnd Func _FindNextFile() Local $n_Array = _GetDirectoryFileList($s_SearchDirectory, $s_SearchExtension) If IsArray($n_Array) Then Local $i_Random_File = Random(1, UBound($n_Array) - 1, 1) Run($s_SearchDirectory & '\' & $n_Array[$i_Random_File]) EndIf EndFunc Func _GetDirectoryFileList($s_Directory = @ScriptDir, $s_Exetension = '*.*') Local $s_Find_File = FileFindFirstFile($s_Directory & '\' & $s_Exetension) Local $a_Array = '' While 1 $s_RunFile = FileFindNextFile($s_Find_File) If @error Then ExitLoop Else $a_Array = $a_Array & $s_RunFile & Chr(01) EndIf WEnd FileClose($s_Find_File) Return StringSplit(StringTrimRight($a_Array, 1), Chr(01)) EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now