I had a pretty simple task I wanted to accomplish: Take a text file and randomly shuffle all the lines in it. This was to be used to shuffle a video playlist on my main system because my video player software was crap and didn't remember its shuffle settings. I decided to put my JavaScript skills to use and learn how to do this via Windows Scripting.

Doing so required a little patience because most of what you want to do with Windows Scripting will depend on Microsoft's object model (similar to the DOM inside a web browser) so there is a learning curve. Personally I think the Microsoft documentation could use some work.

I should use Windows Scripting more. People often tout the fact that with Unix you can do lots of cool things via scripting (i.e. administration tasks, whatever) in languages like Perl, Awk, Python but I don't think it's considered vogue to do Windows Scripting among hardcore geeks, though I believe its capabilities (whether in JavaScript/JScript or VBScript) are pretty mature now. If you don't have a lot of already-written awk/sed/perl/python scripts and you work primarily in Windows, you might want to spend some time learning Windows Scripting, especially if you're comfortable with JavaScript or VisualBasic.

Anyway, the script is located on my forums here. I did a lot of error checking, tried to comment reasonably well and put in the GPL at the top so the script ended up being 87 lines long. To run it, you will need Windows and Windows Scripting 5.6 (download here).

I encourage others who wish to show me up to post their own versions of this task in the forums in other languages (I think it could be done in <20 lines in C++, for instance).

§90 · May 17, 2005 · JavaScript, Software, Technology · · [Print]

Leave a Comment to “Shuffling A Text File”

  1. Rob says:

    Fwiw, lots of people won’t have to upgrade their Windows Script Host (just so this doesn’t sound any harder than it is).
    Have a look at Windows Scripting Controls (wsc files) too, you can make a COM object out of some Javascript.