Is there a way to get the python program to "refresh the sd drive connection"
Question: My daughters SD card has gone corrupt, and I'm trying to recover the
photos/files. I have tried various recover software but to no avail.

However I have found that if I use MSDOS, I can copy various photos, however
intermittently this fails and says "theres no disk in drive" I assuming the
file its trying to copy is corrupt, I can overcome this by pulling out the sd
card and re-inserting it.

So opportunity for a program! :) - I got the file names via dos, created a
text file and knocked up a rough program.... However I keep getting the
"theres no disk in drive"

Hence... Is there a way to get the python program to "refresh the sd drive
connection"

Many thanks.

    
    
    #!/usr/bin/env python
    """ File copy program"""
    
    import os
    import shutil
    
    def main(): 
        Basepathfile = os.path.dirname(os.path.abspath(__file__))
        FileName = 'Filenames.txt'
        PrelimPathFile = os.path.join(Basepathfile, FileName )
        PathFile = os.path.normpath(PrelimPathFile)
    
        Filename1 = open(PathFile, 'r')
        Filename2 = 'c:\\Lili\\'
        for line in Filename1:
            line = line.replace('\r\n', '').replace('\r', '').replace('\n', '')
            Filename1 = 'f:\\DCIM\\Camera\\'+ line
            Filename2 = 'c:\\Lili\\'+ line
    
            try:
                shutil.copy2(Filename1, Filename2)
                print 'Copied... '
                print Filename1, '...to...', Filename2
            except:
                print 'Failed to copy ', Filename1, ' to ', Filename2
    
    if __name__ == '__main__': 
        main() 
    


Answer: This sounds more like a question about Windows than Python. If your SD card is
plugged in via a USB card reader, the easiest approach would probably be to
disable and re-enable the USB hub device it is connected to. This will cause
windows to re-enumerate all the USB devices attached to that hub.

You can do this from the command line with `DevCon`:
<http://support.microsoft.com/kb/311272>

If this is something other than a USB device, I'm not really sure, but maybe
DevCon can still do the trick by trying to disable and re-enable the device
directly.

Alternatively you could try doing it manually with `robocopy`. It has options
not to copy the files it has already copied. You'd still have to manually pull
the SD card a few times, but if you're lucky, the SD card will stay up long
enough to confirm everything was pulled across eventually.

