frew Posted April 1, 2009 Share Posted April 1, 2009 Hello, I have a folder with 10 scripts in it. I want to create a script that will randomly choose one of the ten scripts and run it, short pause, then randomly choose another one of the ten scripts and run it. I don't mind if the same script is run more than once in a row, ie there can be repeats. I tried using Random(1,10, 1) in combination with If Else...ElseIf ...but I was wondering if there might be a better way, since if I get hundreds of scripts to choose from, that's a lot of Ifs and ElseIfs etc. Thank you very much for any ideas. frew Link to comment Share on other sites More sharing options...
stampy Posted April 1, 2009 Share Posted April 1, 2009 Why not use _FileListToArray to build a list of the files in an array. Use random to select a subscript in the array and that would be the file. Link to comment Share on other sites More sharing options...
Marlo Posted April 1, 2009 Share Posted April 1, 2009 #include <File.au3> Dim $iScriptNum, $aFileList = _FileListToArray("Scripts path", "*.au3") While True $iScriptNum = Random(1, $aFileList[0], 1) ;$aFileList[$iScriptNum] will be the path of one of the random scripts. WEnd Maybe something like that? Click here for the best AutoIt help possible.Currently Working on: Autoit RAT Link to comment Share on other sites More sharing options...
frew Posted April 1, 2009 Author Share Posted April 1, 2009 Thanks for the idea stampy. Thanks for the code Marlo. I'm trying to get it to work. It does not seem to run the files though. I saved this as an au3 and ran it but it does nothing: #include <File.au3> Dim $iScriptNum, $aFileList = _FileListToArray("C:\Program Files\AutoIt3\Scripts_AutoIT3_my_1\random chain 1\", "*.au3") While True $iScriptNum = Random(1, $aFileList[0], 1) ;$aFileList[$iScriptNum] will be the path of one of the random scripts. WEnd What else do I need to do? I was hoping to run this script and have the scripts in the folder that I point to above start running at random...one, then another, then another, having them start to run randomly one by one, and when one ends the next randomly chosen au3 runs...on and on like that. Thanks for any other ideas for me to try. frew Link to comment Share on other sites More sharing options...
Nahuel Posted April 1, 2009 Share Posted April 1, 2009 Of course it doesn't work. He didn't give you the whole code, he gave you a way to start. Here would be a closer approach: #include <File.au3> Dim $iScriptNum, $aFileList = _FileListToArray("C:\Program Files\AutoIt3\Scripts_AutoIT3_my_1\random chain 1", "*.au3") While True $iScriptNum = Random(1, $aFileList[0], 1) ;$aFileList[$iScriptNum] will be the path of one of the random scripts. ShellExecute($aFileList[$iScriptNum],"","","Run") WEnd Get used to not using trailing backslashes. Link to comment Share on other sites More sharing options...
stampy Posted April 1, 2009 Share Posted April 1, 2009 You'll need to add a call or run to the code. Right now it only picks a random number but then does nothing with it. #include <File.au3> Dim $iScriptNum, $aFileList = _FileListToArray("Scripts path", "*.au3") While True $iScriptNum = Random(1, $aFileList[0], 1);<<<<<pick the random number ;$aFileList[$iScriptNum] will be the path of one of the random scripts. ;runwait - call - run here <<<<<<<<<<<<<<<<<<<<<< command to do something here. ;the choice will depend on what you want it to do and what format your scripts are in. ;ie: runwait($aFileList[$iScriptNum]) .......... something like that WEnd Link to comment Share on other sites More sharing options...
frew Posted April 1, 2009 Author Share Posted April 1, 2009 Thank you very much Nahuel for the extra code. And thank you stampy for your clarification. Okay, this works! Very nice. I just had to tinker around with it a bit. Turns out what was throwing me off a bit too was that, (perhaps just on my older system Windows 98SE), nothing worked if the .au3 files had spaces in their names. Also, he whole macro thing is a bit tricky (the path,or filename? as a parameter?...in helpfile)...but it turns out if I put the path after the $aFileList[$iScriptNum], then it works. #include <File.au3> Dim $iScriptNum, $aFileList = _FileListToArray("C:\Program Files\AutoIt3\Scripts_AutoIT3_my_1\random chain 1", "*.au3") While True $iScriptNum = Random(1, $aFileList[0], 1) ;$aFileList[$iScriptNum] will be the path of one of the random scripts. ShellExecute(@AutoItExe, $aFileList[$iScriptNum], "C:\Program Files\AutoIt3\Scripts_AutoIT3_my_1\random chain 1") Sleep(5000) WEnd Thanks again so much for your help with this. frew Link to comment Share on other sites More sharing options...
Valuater Posted April 1, 2009 Share Posted April 1, 2009 This should fix any "space" problem... #include <File.au3> Dim $iScriptNum, $aFileList = _FileListToArray("C:\Program Files\AutoIt3\Scripts_AutoIT3_my_1\random chain 1", "*.au3") While True $iScriptNum = Random(1, $aFileList[0], 1) $Runner = FileGetShortName($aFileList[$iScriptNum]) ; will be the path of one of the random scripts. ShellExecute(@AutoItExe, $Runner, "C:\Program Files\AutoIt3\Scripts_AutoIT3_my_1\random chain 1") Sleep(5000) WEnd 8) Link to comment Share on other sites More sharing options...
frew Posted April 2, 2009 Author Share Posted April 2, 2009 Hmmm....does not work here. Thank you though Valuater. I run that script and it works fine when the three files in the folder have underscores, no spaces. When I rename them replacing the underscores with spaces, I get AutoIt Error Line 0 (File "C:\Program Files\AutoIt3\Scripts_AutoIt3_my_1\random chain 1\C"): Error: Error opening the file. Could me using Windows 98SE have anything to do with it? (I know...) Thank you very much for any other ideas. For now I may just be sure to create script names with no spaces in them. frew 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