Sign in to follow this  
Followers 0

just a lil help.

6 posts in this topic

#1 ·  Posted (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)
EndFunc

This will Only Run 1 File, how would i make it Search for .exe randomly and run it?.

Edited by NegativeNrG

[size=20]My File Upload[/size]Register at my site and upload.

Share this post


Link to post
Share on other sites



#2 ·  Posted

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

[center]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.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by NegativeNrG

[size=20]My File Upload[/size]Register at my site and upload.

Share this post


Link to post
Share on other sites

#4 ·  Posted

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)
EndFunc
This is untested....


[center]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.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted

ok, i just tested it and successfully worked. Thanks alot Smokey.


[size=20]My File Upload[/size]Register at my site and upload.

Share this post


Link to post
Share on other sites

#6 ·  Posted

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

[center]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.[/center]

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