I want my script to tell if the removable disk is an SD card or not, so I wrote 
the following script.

buf_fmt='HHLLLL'  
buf_size=struct.calcsize(buf_fmt)

drives = (drive for drive in win32api.GetLogicalDriveStrings ().split 
("\\\000") if drive)
        for drive in drives:
            if win32file.GetDriveType (drive)==2:
                print "Removable Disk" , drive
                if 'A' in drive:
                    print "floppy"
                else:
                    drive="\\\\.\\"+drive+'.'
    print drive
                    hVol = win32file.CreateFile(drive, 
win32con.GENERIC_READ|win32con.GENERIC_WRITE,
                        win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE, 
None, win32con.OPEN_EXISTING,
                        0, None)
                    if hVol == win32file.INVALID_HANDLE_VALUE:   
                        print "could not open device"                      

                    buf=win32file.DeviceIoControl(hVol, 
winioctlcon.IOCTL_SFFDISK_QUERY_DEVICE_PROTOCOL,None,buf_size,None)
                    size_SFFDISK, reserved_SFFDISK, 
protocolGUID_SFFDISK=struct.unpack(buf_fmt, buf)                    
                    
            else:
                print "Not a removable disk:" , drive    

I printed out the drive letter in the script and checked the letter with the SD 
card letter on win7. The letters are the same. However, as I mentioned, I 
get (1, 'DeviceIoControl', 'Incorrect function').


Thank you,
Jane
>
> Thank you for your help.  
> Could you please help me write better codes for GUID? What are you going to 
> do with it?  You will get back a 20-byte string. 
The last 16-bytes are the binary GUID.  The way you handle that depends
on what you need to do with it. > You are right. I was using USB. 
> Based on your suggestion, I connected the SD drive directly to a PCI
> bus and set buf_fmt='HHLLLL'. However, I got another error message:
> (1, 'DeviceIoControl', 'Incorrect function'). I think I did not use
> the function correctly. How are you specifying the volume?  You should be 
> using a string like
"\\\\.\\E:" to open the volume for the E: drive (where the backslashes
are doubled because of Python's string escaping). I get "incorrect function" if 
I try to use this on a standard disk drive.
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to