Jump to content

[CLOSED] Is there a way to do this in AutoIt?


Recommended Posts

Does anyone have a similar script to this AutoHotKey (AHK) one but in AutoIt? This one is simple and easy but I'd like to edit in but am not good at all in AHK.

fileread, cotoleng, C:\DB\xxx.m3u
FileDelete, C:\DB\xxx.m3u
sort cotoleng, random U
FileAppend, %cotoleng%, C:\DB\xxx.m3u

I know someone, somewhere, will have something that does the same thing.

Thanks! :P

Edited by Diana (Cda)
Link to comment
Share on other sites

#include <File.au3>

$cotoleng = FileRead ('C:\DB\xxx.m3u')
FileDelete('C:\DB\xxx.m3u')
$cotoleng = StringSplit($cotoleng, @CRLF, 1)
_ArrayRandomize($cotoleng)
_FileWriteFromArray ('C:\DB\xxx.m3u',$cotoleng)

Problem is that in AutoIt there is no _ArrayRandomize() function,

there is only _ArraySort()

Edited by Zedna
Link to comment
Share on other sites

#include <File.au3>

$cotoleng = FileRead ('C:\DB\xxx.m3u')
FileDelete('C:\DB\xxx.m3u')
$cotoleng = StringSplit($cotoleng, @CRLF, 1)
_ArrayRandomize($cotoleng)
_FileWriteFromArray ('C:\DB\xxx.m3u',$cotoleng)

Problem is that in AutoIt there is no _ArrayRandomize() function,

there is only _ArraySort()

Hi, thanks very much for your response. Your comment about there not being any _ArrayRandomize function, is that why this doesn't work? If so, I'm confused as to what the script will accomplish ... <g> Due to the above, I'm guessing, that's why I get this error:
---------------------------
AutoIt Error
---------------------------
Line 5  (File "L:\alarm,TaskScheduler - PUAC v2.0.7\APP- PUAC v2.0.7\Playlist (randomize).au3"):

$cotoleng = fileread($File)FileDelete($File)
$cotoleng = ^ ERROR

Error: Error in expression.
---------------------------
OK   
---------------------------
I put in relative paths to the m3u file but even with full paths, which I tested, I get the same error.

Does that mean there is no way to get this to work?

Thanks. :P

Link to comment
Share on other sites

Hi, thanks very much for your response. Your comment about there not being any _ArrayRandomize function, is that why this doesn't work? If so, I'm confused as to what the script will accomplish ... <g> Due to the above, I'm guessing, that's why I get this error:

---------------------------
AutoIt Error
---------------------------
Line 5  (File "L:\alarm,TaskScheduler - PUAC v2.0.7\APP- PUAC v2.0.7\Playlist (randomize).au3"):

$cotoleng = fileread($File)FileDelete($File)
$cotoleng = ^ ERROR

Error: Error in expression.
---------------------------
OK   
---------------------------
I put in relative paths to the m3u file but even with full paths, which I tested, I get the same error.

Does that mean there is no way to get this to work?

Thanks. :P

You must open the file first in order to read...

FileOpen ( "filename", 0)

and you can implement an _ArrayRandomize() using the function Random(). (Search in help)

Edited by Chapi
Link to comment
Share on other sites

You must open the file first in order to read...

FileOpen ( "filename", 0)

In simple case like this you can call directly FileRead without FileOpen.

and you can implement an _ArrayRandomize() using the function Random(). (Search in help)

Random() gives you just one random number it will not randomize array.

@Diana: My pseudocode is OK except call of _ArrayRandomize()

You badly copied my code into Scite

Edited by Zedna
Link to comment
Share on other sites

@Diana: My pseudocode is OK except call of _ArrayRandomize()

You badly copied my code into Scite

I don't see where, sorry. I did a straight copy>paste, I never type in code for that very reason as it's so easy to mess it up.

Ah, so it _is_ some form of "pseudocode" <sigh>. Ah well, I'll just have to go back to the AHK solution. It's simple and I understand it, unlike working with all that array business. I only don't know how to do a variable in AHK but if I can figure that out, the original AHK script will work beautifully and very simply. At least till I get better at AI than I am. I've come a long way slowly but all those array things still confound me. Ah well, so much did just 6 months ago still, so I'll just have to wait till my knowledge catches up and I can come back to this one.

And I do so love the bit about the repeated and repeated "check the help file" phrase; yes, it's great we have it but it's a whole other problem ... Figuring out the help file is often as difficult as figuring out AI itself! <lol> (Besides, been there, done that <g>.)

Thanks. :P

Link to comment
Share on other sites

In simple case like this you can call directly FileRead without FileOpen.

Random() gives you just one random number it will not randomize array.

@Diana: My pseudocode is OK except call of _ArrayRandomize()

You badly copied my code into Scite

What part of "you can implement it..." is hard to understand??

I mean using the function Random() any one can mix the elements of an array.

ie:

Func _ArrayRandomize($array)
Local $random, $aux
    For $I = 0 To 100  ;replace 100 whit your array lengt
        $random = Random (0, 100, 1)
        $aux = $array[$random]
        $array[$random] = $array[$I]
        $array[$I] = $aux
    Next
EndFunc

Or something like that...

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