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

.



Relevant Pages

  • Re: usb disk insists on being readonly
    ... about 400Mbytes of disk and the usb port is USB 1 (that manual doesn't ... disk is connected through a hub. ... touch: cannot touch `a': Read-only file system ... be also readable if I hook it up to a windows machine. ...
    (comp.os.linux.setup)
  • Re: USB Storage Device not functoning
    ... I'm having an almost identical problem with my HandySteno HC202 1 gig USB ... problem lies in the way Windows issues/reserves drive letters. ... I have an Easy Disk 512MB USB Storage Device which works absolutely fine on ...
    (microsoft.public.windowsxp.hardware)
  • Re: Windows unable to boot - black screen
    ... I purchased the USB hard disk enclosue ($55 at Best ... restored Windows on the Toshiba laptop, ...
    (microsoft.public.windowsxp.general)
  • Re: Bradbury: "too many internets"
    ... there's enough room to run normal Windows. ... An SSD that is useful as a main drive for someone who doesn't bimm ... Netbooks had an artificial maximum disk drive size limit if you were ... I think you can find keen prices for USB flash memory - Amazon? ...
    (rec.arts.sf.written)
  • Re: The Daily Blue Screen of Death
    ... > Certainly seems to be a problem with a USB device, ... > General USB Troubleshooting in Windows XP ... the computer runs through a check disk of a secondary ... >> Speculator, NY 12164 ...
    (microsoft.public.windowsxp.general)