Elliotest Posted March 16, 2017 Share Posted March 16, 2017 Hello, I started autoit few days ago, and I'm trying to do something, but I need to explain first what my script do. So I have this: ShellExecute ($path & "\" & $array[Random (1,114,1)]) It executes a random file from the 114 files in the folder's path. So what I'm trying to do, is to save each file it has open in a ini file (just the file array number), so that it will not open it again the next time it will execute. And then when it has opened all files, it deletes all file's number from the ini. I already searched on google, but even the ShellExecute it was hard to find how, so I'm requesting your help for this. Thank you in advance for your help ! Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted March 16, 2017 Moderators Share Posted March 16, 2017 @Elliotest rather than doing Random, if you are just cycling through the array of files, why not just use _ArrayShuffle? You can then cycle through the shuffled array at your leisure. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
kylomas Posted March 16, 2017 Share Posted March 16, 2017 If u are trying to prevent running the same file consecutively use an array to store the file numbers that have been run no need for an ini file unless you need to save these across instances of your script. Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Elliotest Posted March 16, 2017 Author Share Posted March 16, 2017 That the point I want to save it for further instances. Link to comment Share on other sites More sharing options...
Subz Posted March 16, 2017 Share Posted March 16, 2017 Whats your code so far? Link to comment Share on other sites More sharing options...
Elliotest Posted March 16, 2017 Author Share Posted March 16, 2017 #include <File.au3> #include <FileConstants.au3> $Boucle = 0 $path = "C:\Users\Elliotest\Music" $array = _FileListToArray ($path,"*",1) While $Boucle = 0 ShellExecute ($path & "\" & $array[Random (1,114,1)]) Sleep (30000) WinClose ("[CLASS:QWidget]","") WEnd For now there is not utility that is why I want to save files in a ini so that next time I start my program it won't open the same file. Link to comment Share on other sites More sharing options...
Elliotest Posted March 16, 2017 Author Share Posted March 16, 2017 Sorry for the double post, but how to make my script save the value from the Random $array from the ShellExecute ? This way I could easily save it no ? Link to comment Share on other sites More sharing options...
Subz Posted March 16, 2017 Share Posted March 16, 2017 Something like this maybe? While Boucie = 0 $iRandom = Random(1,114,1) If IniRead("Filename.ini", "Shuffle", $iRandom, "") = "" Then Continueloop ShellExecute($path & "\" & $array[$iRandom]) IniWrite("Filename.ini", "Shuffle", $iRandom, $array[$iRandom]) Sleep(30000) WinClose("[CLASS:QWIDGET]", "") WEnd Elliotest 1 Link to comment Share on other sites More sharing options...
Elliotest Posted March 16, 2017 Author Share Posted March 16, 2017 Just now, Subz said: Something like this maybe? While Boucie = 0 $iRandom = Random(1,114,1) If IniRead("Filename.ini", "Shuffle", $iRandom, "") = "" Then Continueloop ShellExecute($path & "\" & $array[$iRandom]) IniWrite("Filename.ini", "Shuffle", $iRandom, $array[$iRandom]) Sleep(30000) WinClose("[CLASS:QWIDGET]", "") WEnd I test this immediatly ! Link to comment Share on other sites More sharing options...
Elliotest Posted March 16, 2017 Author Share Posted March 16, 2017 It doesn't do what exactly I wanted but you helped me a lot ! Now I can write which array was started ! Link to comment Share on other sites More sharing options...
Elliotest Posted March 16, 2017 Author Share Posted March 16, 2017 So when I launch the script it doesn't work, in fact it reads only the file that are already opened in the ini. And the problem is that is must do the opposite, if a file is already in the ini, it must not open and open another file. My brain is exploding right now... Link to comment Share on other sites More sharing options...
Subz Posted March 16, 2017 Share Posted March 16, 2017 (edited) Can you try something like this: #include <Array.au3> #include <File.au3> #include <FileConstants.au3> Local $iMusic Local $sMusic = "C:\Users\Elliotest\Music" Local $aMusic = _FileListToArrayRec($sMusic,"*.mp3",1, 1, 0, 2) Local $sShuffle = @ScriptDir & '\Music.ini' _PlayShuffle(114) Func _PlayShuffle($iPlayList) Local $i = 0 Do $iMusic = Random(1, $aMusic[0], 1) If IniRead($sShuffle, "Shuffle", $iMusic, "Unplayed") = "Unplayed" Then ShellExecute ($aMusic[$iMusic]) IniWrite($sShuffle, "Shuffle", $iMusic, $aMusic[$iMusic]) Sleep (30000) WinClose ("[CLASS:QWidget]","") $i+=1 EndIf Until $i = $iPlayList EndFunc Edited March 16, 2017 by Subz Changed Random Flag to $aMusic[0] Link to comment Share on other sites More sharing options...
Elliotest Posted March 16, 2017 Author Share Posted March 16, 2017 Oh god it works ! Thank you so much for your help ! 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