gpt4 book ai didi

python - WindowsError : [Error 123] The filename, 目录名称或卷标语法不正确: '\\\\buildloc\\kernel\\*.patch/*.*'

转载 作者:太空宇宙 更新时间:2023-11-04 10:43:23 28 4
gpt4 key购买 nike

我正在尝试从内核文件夹复制 *.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()

最佳答案

您的问题很简单:\\buildloc\kernel\*.patch/*.* 不是目录名称。 Windows 文件名不能包含星号和其他禁用字符。 shutil.copytree() 需要目录名;它不进行通配。

如果您打算从名称以 .patch 结尾的目录中复制所有文件,一种方法是使用类似 glob.glob 的文件来标识目录您需要,然后 shutil.copytree() 复制这些目录中的每一个。另一个想法是用 copytree 提供一个回调函数来过滤掉你不想要的目录。

关于python - WindowsError : [Error 123] The filename, 目录名称或卷标语法不正确: '\\\\buildloc\\kernel\\*.patch/*.*',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19194022/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com