Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > recognize a drive as removable media (e.g. compact flash, sd cardor usb drive)

Reply
Thread Tools

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

 
 
Mike Joyce
Guest
Posts: n/a
 
      04-08-2006
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
 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      04-08-2006
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
 
Reply With Quote
 
 
 
 
Tim Golden
Guest
Posts: n/a
 
      04-08-2006
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

 
Reply With Quote
 
Gordon Rainsford
Guest
Posts: n/a
 
      05-03-2006
Tim Golden <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removable media drive DanR Windows 64bit 2 05-15-2010 03:00 PM
Re: Eject a Removable USB drive Mark Hammond Python 3 03-10-2009 08:52 PM
Removable CD drive / floppy drive not recognised BertieBigBollox@gmail.com Computer Support 4 09-08-2007 06:07 AM
Acronis True Image 8.0 boot media wont recognize USB mouse Father Ted Crilly Computer Support 3 04-19-2007 11:05 AM
Install XP x64 with removable C drive & Raid1 E Drive Larry Windows 64bit 10 04-15-2006 01:41 AM



Advertisments