我希望能够遍历一个文本文件中每一行现有路径和文件名的字符串,将其分为驱动器、路径和文件名。然后我想要做的是将这些带路径的文件复制到一个新位置——可以是不同的驱动器,也可以是附加到现有文件树中(即如果S:\A\B\C\D\E\F.shp是原始文件,则将其附加到新位置C:\users\visc\A\B\C\D\E\F.shp)。
由于我的编程技能差,我一直收到以下错误:
这是我的代码:
由于我的编程技能差,我一直收到以下错误:
File "C:\Users\visc\a\b.py", line 28, in <module>
(destination) = os.makedirs( pathname, 0755 );
这是我的代码:
import os,sys,shutil
## Open the file with read only permit
f = open('C:/Users/visc/a/b/c.txt')
destination = ('C:/Users/visc')
# read line by line
for line in f:
line = line.replace("\\\\", "\\")
#split the drive and path using os.path.splitdrive
(drive, pathname) = os.path.splitdrive(line)
#split the path and fliename using os.path.split
(pathname, filename) = os.path.split(pathname)
#print the stripped line
print line.strip()
#print the drive, path, and filename info
print('Drive is %s Path is %s and file is %s' % (drive, pathname, filename))
(destination) = os.makedirs( pathname, 0755 );
print "Path is Created"
谢谢您
Traceback (most recent call last): File "C:\Users\visc\a\b.py", line 28, in <module> (destination) = os.makedirs( pathname, 0755 ); File "C:\Python26\ArcGIS10.0\lib\os.py", line 157, in makedirs mkdir(name, mode) WindowsError: [Error 183] Cannot create a file when that file already exists: '\\A\\B\\C\\D\\E'
- Visceral