Skip to content Skip to sidebar Skip to footer

Python How To Detect A New Piece Of Media In The Cd?

I have a need to copy a group of files. Unfortunately these files will span multiple DVDs. What I want to do is a) copy the files of the current DVD b) when complete, eject the

Solution 1:

I ended up using a combination of wmi and ctypes

import wmi
import os
import time
import wx
import ctypes

app = wx.PySimpleApp(0)
c = wmi.WMI()

for cdrom in c.Win32_CDROMDrive():
    status = cdrom.MediaLoaded
    drive = cdrom.Drive


checkFile = os.path.join(drive,'IWPCpatch-2','install.zip')
print checkFile

testForFile = os.path.exists(checkFile)
while testForFile == False:
    print'file present', testForFile

    for cdrom in c.Win32_CDROMDrive():
        status = cdrom.MediaLoaded
        print'Media present', status

    #Eject
    ctypes.windll.WINMM.mciSendStringW(u"set cdaudio door open", None, 0, None)

    #Warn
    sMessage = """ Please insert the media that contains the file """ + checkFile

    successWarning = wx.MessageBox(sMessage, "WARNING")

    #wait for new cdfor cdrom in c.Win32_CDROMDrive():
        status = cdrom.MediaLoaded
        print'Media present', status

    while status == False:
        for cdrom in c.Win32_CDROMDrive():
            status = cdrom.MediaLoaded
            print'Media present', status
        time.sleep(5)

    #test and exit loop or restart
    testForFile = os.path.exists(checkFile)


print'FILE PASSED'

Solution 2:

pygame has a module for managing the CD/DVD drive: http://www.pygame.org/docs/ref/cdrom.html

Solution 3:

PyMedia looks like it has what you need.

Post a Comment for "Python How To Detect A New Piece Of Media In The Cd?"