Wednesday, 25 September 2013

Python script to copy data from an external drive

Python script to copy data from an external drive

I am in the process of writing a a python program to move user profile
data from an externally attached HD to a new computer. I am currently
having trouble getting the python script to recognize the external drive.
The file path seems accurate, but I am getting an error:
Traceback (most recent call last):
File "C:\Users\Eric\Documents\KoelCopy\KoelCopy.py", line 9, in <module>
distutils.dir_util.copy_tree(source, destination)
File "C:\Python33\lib\distutils\dir_util.py", line 124, in copy_tree
"cannot copy tree '%s': not a directory" % src)
distutils.errors.DistutilsFileError: cannot copy tree 'F:\Users\Nick\My
Documents': not a directory
My code is as follows:
import distutils.core
input_source = input('Enter User Name: ')
source_drive = input('Enter source drive letter: ')
directories = ["\\My Documents", "\\Favorites", "\\Desktop"]
for directory in directories:
source = source_drive + ':\\Users\\' + input_source + directory
destination = 'C:\\Users\\' + input_source + directory
distutils.dir_util.copy_tree(source, destination)
I have also noticed if I get this to work coping from the C drive to C
drive I am getting access denied errors. Would this be caused by windows
security or should I be using a different copy command? I also noticed
when I tested just copying the Desktop is was getting an access denied
error on just the desktop.ini file. How would I exclude such files? I know
I have a lot of questions, I appreciate your time.
Thanks!

No comments:

Post a Comment