我正在尝试从内核文件夹中复制* .patch文件并运行到以下错误
Traceback (most recent call last):
File "copytest.py", line 47, in <module>
main()
File "copytest.py", line 44, in main
copystuff(src,dest)
File "copytest.py", line 18, in copystuff
shutil.copytree(src, dest)
File "C:\CRMApps\apps\Python262\lib\shutil.py", line 140, in copytree
names = os.listdir(src)
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: '\\\\buildloc\\kernel\\*.patch/*.*'
代码: -
import argparse
import shutil, errno
import os
def copystuff(src, dest):
#print "IN COPY STUFF"
if os.path.isfile(src):
dest_dirname = os.path.dirname(dest)
#print "DEST DIR NAME" + dest_dirname
if not os.path.isdir(dest_dirname):
# print "MAKING DEST DIR"
os.makedirs(dest_dirname)
print src
print dest
shutil.copy2(src, dest)
else:
print src
print dest
shutil.copytree(src, dest)
def main ():
copy_list=[r'\kernel\*.patch']
#copy_list=['out\target\product\msm8226\obj\KERNEL_OBJ\vmlinux']
parser = argparse.ArgumentParser(description='This is copy binaries for android build script)
parser.add_argument('-v','--build_version',action='store',dest='build_version',help='<Required> Build version',required=True)
parser.add_argument('-s','--source',action='store',dest='source',help='<Required> source path',required=True)
parser.add_argument('-d','-destination',action='store',dest='destination',help='<Required>destination path',required=True)
results = parser.parse_args()# collect cmd line args
build_version = results.build_version
print "BUILD_VERSION: " + build_version
source = results.source
print "SOURCE PATH: " + source
destination = results.destination
print "DESTINATION PATH: " + destination
dest_fastboot= destination + r'\out\target\product\msm8226'
if not os.path.isdir(dest_fastboot):
# print "MAKING DEST DIR"
os.makedirs(dest_fastboot)
shutil.copy2('Fastboot_load.bat', dest_fastboot)
for item in copy_list:
item = item.strip()
print "ITEM: " + item
src = source + item
dest = destination + item
copystuff(src,dest)
if __name__ == '__main__':
main()
答案 0 :(得分:4)
您的问题很简单:\\buildloc\kernel\*.patch/*.*
不是目录的名称。 Windows文件名不能包含星号,以及其他禁用的字符。 shutil.copytree()
需要目录的名称;它不做全球化。
如果您的目的是从名称以.patch
结尾的目录中复制所有文件,一种方法是使用类似glob.glob
的内容来识别您想要的目录,然后shutil.copytree()
复制每个目录。另一个想法是提供一个带copytree
的回调函数来过滤掉你不想要的目录。