Diana (Cda) Posted October 15, 2008 Share Posted October 15, 2008 (edited) 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! Edited October 16, 2008 by Diana (Cda) Link to comment Share on other sites More sharing options...
Zedna Posted October 15, 2008 Share Posted October 15, 2008 (edited) #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 October 15, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Diana (Cda) Posted October 15, 2008 Author Share Posted October 15, 2008 #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. Link to comment Share on other sites More sharing options...
Chapi Posted October 15, 2008 Share Posted October 15, 2008 (edited) 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. 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 October 15, 2008 by Chapi Link to comment Share on other sites More sharing options...
Zedna Posted October 15, 2008 Share Posted October 15, 2008 (edited) 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 October 15, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Diana (Cda) Posted October 16, 2008 Author Share Posted October 16, 2008 @Diana: My pseudocode is OK except call of _ArrayRandomize()You badly copied my code into SciteI 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. Link to comment Share on other sites More sharing options...
Zedna Posted October 16, 2008 Share Posted October 16, 2008 (edited) Ah, so it _is_ some form of "pseudocode" <sigh>. Ah well,It's pseudocode just due to call of not existting _ArrayRandomize()Except of that it's normal code. Edited October 16, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
ResNullius Posted October 16, 2008 Share Posted October 16, 2008 Check out:http://www.autoitscript.com/forum/index.php?showtopic=67777weaponx also has a post linked to in there which looks like it would work well. Link to comment Share on other sites More sharing options...
Chapi Posted October 16, 2008 Share Posted October 16, 2008 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 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