1import os
2import shutil
3sourcePath = r'C:\Users\...\What_to_copy_to_phone'
4destPath = r'Computer\XT1032\Internal storage'
5for root, dirs, files in os.walk(sourcePath):
6
7#figure out where we're going
8dest = destPath + root.replace(sourcePath, '')
9
10#if we're in a directory that doesn't exist in the destination folder
11#then create a new folder
12if not os.path.isdir(dest):
13 os.mkdir(dest)
14 print 'Directory created at: ' + dest
15
16#loop through all files in the directory
17for f in files:
18
19 #compute current (old) & new file locations
20 oldLoc = root + '\\' + f
21 newLoc = dest + '\\' + f
22
23 if not os.path.isfile(newLoc):
24 try:
25 shutil.copy2(oldLoc, newLoc)
26 print 'File ' + f + ' copied.'
27 except IOError:
28 print 'file "' + f + '" already exists'