recognize a drive as removable media (e.g. compact flash, sd cardor usb drive)

Discussion in 'Python' started by Mike Joyce, Apr 8, 2006.

  1. Mike Joyce

    Mike Joyce Guest

    I am trying to write a portable script that will find removable media,
    such as compact flash, sd card, usb, etc. drive and then upload files
    from the media. I want this to be portable so that I can write and
    maintain one program for both Linux and Windows. Each platform uses
    different functions so even if I could find two platform dependent
    functions that would be fine. Basically, I would like to avoid checking
    fixed disks if possible.
    If anyone know of a good way to do this please let me know. Thanks in
    advance for any help.
    -Mike Joyce
     
    Mike Joyce, Apr 8, 2006
    #1
    1. Advertising

  2. Mike Joyce

    Larry Bates Guest

    Re: recognize a drive as removable media (e.g. compact flash, sdcard or usb drive)

    Mike Joyce wrote:
    > I am trying to write a portable script that will find removable
    > media, such as compact flash, sd card, usb, etc. drive and then upload
    > files from the media. I want this to be portable so that I can write and
    > maintain one program for both Linux and Windows. Each platform uses
    > different functions so even if I could find two platform dependent
    > functions that would be fine. Basically, I would like to avoid checking
    > fixed disks if possible.
    > If anyone know of a good way to do this please let me know. Thanks
    > in advance for any help.
    > -Mike Joyce


    Take a look at the code located at the top of the os.py module. It
    goes through a series of tests to determine which OS it is running
    on. You should be able to use something like that to create branches
    in your code to handle Windows/Linux separately. As far as determining
    removable drives in Windows/Linux I'm afraid I can't help on that.

    -Larry Bates
     
    Larry Bates, Apr 8, 2006
    #2
    1. Advertising

  3. Mike Joyce

    Tim Golden Guest

    Re: recognize a drive as removable media (e.g. compact flash, sd card or usb drive)

    Mike Joyce wrote:
    > I am trying to write a portable script that will find removable media,
    > such as compact flash, sd card, usb, etc. drive and then upload files
    > from the media. I want this to be portable so that I can write and
    > maintain one program for both Linux and Windows. Each platform uses
    > different functions so even if I could find two platform dependent
    > functions that would be fine. Basically, I would like to avoid checking
    > fixed disks if possible.
    > If anyone know of a good way to do this please let me know. Thanks in
    > advance for any help.


    Under Windows, you can probably use WMI for this, depending on
    exactly what it is you're trying to do. If I read you right, you want
    to
    scan all devices, determine the removable ones, and then read stuff
    off them.

    If that's right, then something like this might do the trick on Windows
    (untestedish - picks up my floppy and USB stick):

    <code>
    import wmi
    c = wmi.WMI ()
    removable_disks = c.Win32_LogicalDisk (DriveType=2)
    # if you want CDROM as well, repeat with DriveType=5
    </code>

    This will give you a list of WMI objects, each corresponding
    to a removable disk. You can access the drive letter via the
    objects' .Name attributes, and do an os.walk or whatever on
    them.

    <code>
    import os
    for disk in removable_disks:
    for dirpath, dirnames, filenames in os.walk (disk.Name + "\\"):
    print dirpath # and do whatever else you want
    </code>

    TJG
     
    Tim Golden, Apr 8, 2006
    #3
  4. Re: recognize a drive as removable media (e.g. compact flash, sd card or usb drive)

    Tim Golden <> wrote:

    > Mike Joyce wrote:
    > > I am trying to write a portable script that will find removable media,
    > > such as compact flash, sd card, usb, etc. drive and then upload files
    > > from the media. I want this to be portable so that I can write and
    > > maintain one program for both Linux and Windows. Each platform uses
    > > different functions so even if I could find two platform dependent
    > > functions that would be fine. Basically, I would like to avoid checking
    > > fixed disks if possible.
    > > If anyone know of a good way to do this please let me know. Thanks in
    > > advance for any help.

    >
    > Under Windows, you can probably use WMI for this, depending on
    > exactly what it is you're trying to do. If I read you right, you want
    > to
    > scan all devices, determine the removable ones, and then read stuff
    > off them.


    Any suggestions as to doing this on a Mac?


    --
    Gordon Rainsford
     
    Gordon Rainsford, May 3, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Heiko Selber

    Name/ID of removable Media: how?

    Heiko Selber, Apr 19, 2005, in forum: Python
    Replies:
    4
    Views:
    2,110
    Claudio Grondi
    Apr 19, 2005
  2. Tim Golden

    RE: Name/ID of removable Media: how?

    Tim Golden, Apr 19, 2005, in forum: Python
    Replies:
    1
    Views:
    357
    Heiko Selber
    Apr 19, 2005
  3. Tim Golden

    RE: Name/ID of removable Media: how?

    Tim Golden, Apr 19, 2005, in forum: Python
    Replies:
    0
    Views:
    364
    Tim Golden
    Apr 19, 2005
  4. glenn

    analyzing removable media

    glenn, Sep 29, 2006, in forum: Python
    Replies:
    8
    Views:
    346
    glenn
    Sep 30, 2006
  5. Mark Hammond

    Re: Eject a Removable USB drive

    Mark Hammond, Mar 9, 2009, in forum: Python
    Replies:
    3
    Views:
    749
    Mark Hammond
    Mar 10, 2009
Loading...

Share This Page