[Tutor] CD ROM Drive

Neven Goršić neven.gorsic at gmail.com
Wed Jul 16 14:40:11 CEST 2008


On Wed, Jul 16, 2008 at 2:02 PM, Tim Golden <mail at timgolden.me.uk> wrote:
> Neven Goršić wrote:
>>
>> Hi!
>>
>> I am using Python 2.5.2 on WinXP Pro and I want to detect all disk drives.
>> I have C:, D: and E: hard disks and F: DVD ROM.
>
> Use WMI:
>
> http://timgolden.me.uk/python/wmi_cookbook.html#find-drive-types
>
> (mutatis mutandis)
>
>
>> When I try to use os.access method with writing checking I get True
>> testing DVD ROM Drive with DVD media inside (which is not writable).
>> 1. Why? DVD disk is not writable!
>>
>>>>> import os
>>>>> print os.access('F:\\',os.W_OK)
>>
>> True
>
> In short because os.access always returns True for
> *directories* as opposed to *files* on Windows
> because it only checks the read-only flag and the
> read-only flag has no real meaning on a directory
> on Windows.
>
>> 2. When I remove DVD Disk from the drive I get unswer False.
>
>
> It returns False when there's no media because that
> constitutes an exception from the OS and the function
> automatically returns False in that case.
>
> [... snip stuff about "Insert disk..." ...]
>
> Frankly this is a bit tricky. I'm not sure to what extent you can
> get in ahead of the shell. A couple of possibilities, assuming
> I've understood the situation. You can monitor device insertion
> and removal either via the Win32 or shell APIs or via WMI (which, I imagine,
> uses that API under the covers). The latest pywin32 modules have
> added more support for this kind of thing, which you previously
> had to do via ctypes.
>
> If you're interested in pursuing this, I can rustle up some code.
>
>> 3. Are there some other way to get list of all disk drives and DVD ROM
>> drives?
>> I hoped that I can do that with modules that comes with standard
>> Python instalation.
>
> See above. Although my solution uses external modules[1][2], you *can* do
> the same using ctypes, but why bother? Just install the
> TJG
>
> [1] http://pywin32.sf.net
> [2] http://timgolden.me.uk/python/wmi.html
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

-------------------------------------------

Thank you for your quick answer. I'll try suggested modules and let you now.

Neven


More information about the Tutor mailing list