Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by Old Pedant View Post
    I think Felgall missed the end of his answer.
    I was concentrating on supplying an exact equivalent to the piece of code posted (and even then missed the i++ between the two calls). Of course a loop would take care of the entire code properly rather than just repeating the calls many times.

    The MSIE solution is probably a good choice in this situation. The file:// references may not work properly in all other browsers so a full cross browser solution doesn't exist.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  2. #17
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    i don't think ones based on document.createElement('script') will work since they will all attach to the dom instantly and i will be maxed out when the script loads...

    you could use document.write() instead of document.createElement('script') since that will pause between each potential drive letter, ensuring i is set on the CD drive when the script is parsed.


    this should also work to get the base path, from which you can determine the drive letter quite easily:

    Code:
    function __filename(){
       try{self.s0m3741ng()}catch(y){
    	return "file://" + 
    	 String(y.fileName || y.file || y.stack || y + '')
    	 .split(/:\d+:\d+/)[0].split("file://")[1];
        } 
    }//end __filename()
    // example usage: alert( __filename() );
    Last edited by rnd me; 01-12-2013 at 02:34 AM.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  3. #18
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    I am going to try/use both methods - thanks!
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  4. #19
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    Trying to implement these ideas and, you know, nothing actually does the job!

    I tried Old Pedant's Active-X method, and, using IE only, it doesn't find the drive.js file on a CD disk in the drive.

    Then I tried felgall's idea (the full version by Old Pedant) and it too doesn't throw up the drive letter.

    And finally tried rnd me's method, and it might work but is only for IE10. Which I don't have.

    Has anyone had better luck with these routines?
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  5. #20
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Willing to experiment a little?

    Try this and see if it works and/or what error you get.

    First of all, put the CD into a *known* drive. In what follows, I'll use "E:" as an example only.
    Code:
    <script>
    function test( )
    {
        try {
            var fso = new ActiveXObject("Scripting.FileSystemObject");
        } catch ( e ) {
            alert("Unable to create FSO: " + e.message );
            return;
        }
        try {
            var dir = fso.GetFolder("E:\\");
        } catch ( e1 ) {
            alert("Unable to access folder: " + e1.message );
            return;
        }
        var flist = "";
        try {
            var fc = new Enumerator(dir.files);
        } catch( e2 ) {
            alert("Could not get enumerator: " + e2.message );
            return;
        }
        try {
            for (; !fc.atEnd(); fc.moveNext())
            {
                flist += "\n" + fc.item();
            }
        } catch( e3 ) { 
            alert("Problem during iteration: " + e3.message );
            return;
        }
        alert("Files found:" + flist );
    }
    test( );
    </script>
    Last edited by Old Pedant; 01-16-2013 at 10:37 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  6. #21
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    And possibly a change in my original code?
    Code:
    function findDriveThatIsPlaying( )
    {
        var drives = "BDEFGHIJKLMNOPQRSTUVWXYZ";
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        for ( var d = 0; d < drives.length; ++d )
        {
            var driveletter = drives[d];
            try {
                if ( fso.FileExists( driveletter + ":\\drive.js" ) )
                {
                    document.cookie="yourdrive="+driveletter+"; path=/";
                    return driveletter;
                }
            } catch ( ignoreError ) { /* do nothing */ }
        }
        // if you get here, no "drive.js" found on any drive
        // what do you want to do???
        return null;
    }
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  7. #22
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    By the by, the problem could well be that MSIE won't let you create the FSO object with standard security settings. That's easy to change, but it might not be a solution you want.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  8. #23
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    i can get the current drive letter like this:
    Code:
    <script>
      alert(location.href.split(":")[1].slice(-1));
    </script>
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  9. #24
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Quote Originally Posted by rnd me View Post
    i can get the current drive letter like this:
    Code:
    <script>
      alert(location.href.split(":")[1].slice(-1));
    </script>
    *** DOH ON ALL OF US ***

    Clearly, if the script in question is playing *FROM* some CD drive, then that should be all that is needed.

    I'm even tempted to burn a CD just to try it, but I'm betting 95% it will work just fine.

    I'm assuming that the CD is an "Autoplay" CD, of course.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  10. #25
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    OP, the test found the files on the E drive.

    The other (updated) script produced nothing though.

    rnd me's little script finds a drive letter (not the drive) but I am not running the script from the CD.

    Thanks - it's all very interesting.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  11. #26
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Quote Originally Posted by tpeck View Post
    OP, the test found the files on the E drive.

    The other (updated) script produced nothing though.
    So you *must* be getting an error from it.

    Have you used the error console in MSIE? It's not quite as good as the one in Chrome, but it's not at all bad.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  12. #27
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Oh, sigh. I should have tried this myself.

    The problem is DROP DEAD obvious!

    I did:
    Code:
    <script>
        var drives = "BDEFGHIJKLMNOPQRSTUVWXYZ";
        ...
            var driveletter = drives[d];
    But MSIE--even MSIE 9--doesn't SUPPORT treating a string as an array of character!

    You just have to change that line to
    Code:
            var driveletter = drives.charAt(d);
    and presto! It all works.

    Again, though, you must have your security settings in MSIE such that "unsafe ActiveX controls" can be used. At the very least, the setting must be "prompt", not "disable". If you feel comfortable doing it, you could use "enable".
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •