我想遍历现有路径和文件名的文本文件中的每一行,将字符串划分为驱动器、路径和文件名。然后我想做的是将文件及其路径复制到新位置 - 不同的驱动器或附加到现有文件树(即,如果 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 );
这是我的代码:
导入操作系统、系统、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"
谢谢