Elliotest

Saving ShellExecute do in a ini

13 posts in this topic

#1 ·  Posted

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

Share this post


Link to post
Share on other sites



#2 ·  Posted

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


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

Share this post


Link to post
Share on other sites

#4 ·  Posted

That the point I want to save it for further instances.

Share this post


Link to post
Share on other sites

#5 ·  Posted

Whats your code so far?

Share this post


Link to post
Share on other sites

#6 ·  Posted

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

Share this post


Link to post
Share on other sites

#7 ·  Posted

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 ?

Share this post


Link to post
Share on other sites

#8 ·  Posted

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

 

1 person likes this

Share this post


Link to post
Share on other sites

#9 ·  Posted

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 !

Share this post


Link to post
Share on other sites

#10 ·  Posted

It doesn't do what exactly I wanted but you helped me a lot ! Now I can write which array was started !

Share this post


Link to post
Share on other sites

#11 ·  Posted

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

Share this post


Link to post
Share on other sites

#12 ·  Posted (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 by Subz
Changed Random Flag to $aMusic[0]

Share this post


Link to post
Share on other sites

#13 ·  Posted

Oh god it works ! :o

Thank you so much for your help ! :P

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