Jump to content

Saving ShellExecute do in a ini


Recommended Posts

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 ! :D

Link to comment
Share on other sites

  • Moderators

@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

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

#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

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

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

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 by Subz
Changed Random Flag to $aMusic[0]
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...