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 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post

    Scan removable disks.

    How would I go about compiling a list of connected devices using JavaScript?

    Including the device "letter" so I can access it.

    For example, if I have 2 PenDrive's connected I would have a list like so:

    pendrive1 -> E:/
    pendrive2 -> F:/

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    I have a better question: How do you expect to able to access any device/drive from JavaScript? Generally speaking, JavaScript can't access any folders or files on the client machine.

    Yes, there are ways around that, especially in MSIE if the browser user is willing to accept "unsafe scripting" by you. But...
    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.

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,454
    Thanks
    0
    Thanked 632 Times in 622 Posts
    What platform are you intending the JavaScript run on - the exact command to use (if there is one) will depend on exactly where the script is running - for example JavaScript has no access whatever to that information if it is running inside a web browser. If the JavaScript is run on Adobe Air then it has access to open files on any device that is attached but the only way I can think of to actually check for attached devices would be to make an attempt to access each drive letter separately.
    Last edited by felgall; 05-07-2013 at 11:26 PM.
    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.

  • #4
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    Well basically I need some way of basically compiling a list of connected devices, then selecting the correct device. This will then upload the contents of the device (a camera for example) to the machine. Not uploading to a server or anything.

    Then the device (camera) will be wiped clean ready for the next batch of photos.

    What is the best way to do this? Whilst using a web browser for the main application.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by martynball View Post
    Well basically I need some way of basically compiling a list of connected devices, then selecting the correct device. This will then upload the contents of the device (a camera for example) to the machine. Not uploading to a server or anything.

    Then the device (camera) will be wiped clean ready for the next batch of photos.

    What is the best way to do this? Whilst using a web browser for the main application.
    you simply use a file input to browse to the device and select the files to upload. you can do a whole drive even, but not more than one drive at once...

    you can get multiple files in most browsers now, but only chrome gives you the ability to upload deep folders... javascript can't delete anything though, so you'll have to do that on the camera by formatting the card or by browsing to the card and deleting the files...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by Old Pedant View Post
    I have a better question: How do you expect to able to access any device/drive from JavaScript?
    Code:
    <input type=file onchange=handle(this.files) />
    or drag and drop if you want to be fancy about it...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • Users who have thanked rnd me for this post:

    martynball (05-07-2013)

  • #7
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    There was a system that a company I used to work for used, although I do not know what language they used, but what it did was compile a list of connected devices, you selected the camera and it then moved the photos from the camera to the computer and then wiped the device.

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by martynball View Post
    Well basically I need some way of basically compiling a list of connected devices, then selecting the correct device. This will then upload the contents of the device (a camera for example) to the machine. Not uploading to a server or anything.

    Then the device (camera) will be wiped clean ready for the next batch of photos.

    What is the best way to do this? Whilst using a web browser for the main application.
    I have to disagree with RndMe on this one.

    You said the magic words there in your last sentence: "...using a web browser for the main application."

    In other words, you really *DO* want to do this on your *OWN COMPUTER* and it is only for your *OWN USE*. Right?

    So you are just looking for a way to avoid writing a real application and doing it all in JavaScript instead.

    And so the answer really is: Use MSIE (only) and it's capability to use ActiveX scripting. And, yes, you will be asked if you want to allow "unsafe scripting", but clearly in this case that's exactly what you want to do.

    The only part that isn't so clean here: You can't format a drive from the available ActiveX components, so far as I know. You could, however, just delete all files. For a camera card or similar, that's not as good as reformatting, but it should work.

    SO...

    You will need to do
    Code:
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    but then just what commands to issue to the fso would take some time to write out, so let me point you to the documentation.
    http://msdn.microsoft.com/en-us/libr...(v=vs.84).aspx

    Most especially, you will want to look here:
    http://msdn.microsoft.com/en-us/libr...(v=vs.84).aspx

    Note that there isn't any method that simply enumerates available drives, but it's not too hard to see how to find all drives:
    Code:
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    
    var driveLetters = "GHIJKLMNOP"; // or any other list of letter you want to check
    for ( var d = 0; d < driveLetters.length; ++d )
    {
        var letter = driveLetters.charAt(d);
        if ( fso.DriveExists( letter )
        {
             document.write( "Drive " + letter + ": found<br/>" );
        }
    }
    (Presumably you wouldn't really use document.write. That was just for demo purposes.)
    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.

  • Users who have thanked Old Pedant for this post:

    martynball (05-07-2013)

  • #9
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    That all sounds like what I want thanks. I would do an actual application, but that involves learning a complete new language.

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    I would also note that you could write this as a JavaScript application, *NOT* using the browser.

    To see how to do that, look here:
    http://msdn.microsoft.com/en-us/libr...(v=vs.84).aspx
    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.

  • Users who have thanked Old Pedant for this post:

    martynball (05-07-2013)

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    It's really pretty simple. You just create a ".js" file and then you can execute it FROM WINDOWS (for example, by dropping a shortcut to it on your desktop).

    Instead of working with browser DOM objects, you work with WShell objects.

    Here's a list of the available objects:
    http://msdn.microsoft.com/en-us/libr...(v=vs.84).aspx

    Primarily you will work with WScript and likely WshShell objects. You might also use WshArguments if you want to pass in arguments on a command line (which can, in turn, be part of the desktop shortcut).
    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.

  • Users who have thanked Old Pedant for this post:

    martynball (05-08-2013)

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Just as a for example, copy/paste this code into a file named "driveDemo.js":
    Code:
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    
    var driveLetters = "EFGHIJKLMNOP"; // or any other list of letter you want to check
    var founddrives = "";
    
    for ( var d = 0; d < driveLetters.length; ++d )
    {
        var letter = driveLetters.charAt(d);
        if ( fso.DriveExists( letter ) )
        {
             founddrives += "Drive " + letter + ": found\n";
        }
    }
    WScript.Echo( founddrives );
    Then use windows explorer or MyComputer to find the folder where you saved that file.

    Then simply double click on that file name.

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

  • Users who have thanked Old Pedant for this post:

    martynball (05-08-2013)

  • #13
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Oh, and finally, if you use this method, then you can invoke the FORMAT command from the WshShell object!

    And so you *could* then re-format the cards/devices.

    But be darned sure you use that with utmost care! You *can* wipe out a hard drive if you use it wrong.
    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.

  • Users who have thanked Old Pedant for this post:

    martynball (05-08-2013)

  • #14
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    Thanks, how would I got about making a GUI for the JavaScript application?

  • #15
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    Just tried to open the file but it is just loading Dreamweaver to start editing it.

    Im going try to get hold of the current system that the company I work for uses just to see how they do it, will let you know.
    Last edited by martynball; 05-08-2013 at 11:45 AM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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