Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

just a lil help.


  • Please log in to reply
5 replies to this topic

#1 NegativeNrG

NegativeNrG

    Prodigy

  • Active Members
  • PipPipPip
  • 169 posts

Posted 10 March 2006 - 10:23 AM

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

Edited by NegativeNrG, 10 March 2006 - 10:23 AM.

My File UploadRegister at my site and upload.







#2 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,866 posts

Posted 10 March 2006 - 10:28 AM

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.


#3 NegativeNrG

NegativeNrG

    Prodigy

  • Active Members
  • PipPipPip
  • 169 posts

Posted 10 March 2006 - 10:32 AM

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 by NegativeNrG, 10 March 2006 - 10:33 AM.

My File UploadRegister at my site and upload.

#4 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,866 posts

Posted 10 March 2006 - 10:45 AM

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).
Plain Text         
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) EndFunc
This 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.


#5 NegativeNrG

NegativeNrG

    Prodigy

  • Active Members
  • PipPipPip
  • 169 posts

Posted 10 March 2006 - 12:00 PM

ok, i just tested it and successfully worked. Thanks alot Smokey.
My File UploadRegister at my site and upload.

#6 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,866 posts

Posted 10 March 2006 - 12:41 PM

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's
Plain Text         
Global $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.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users