我正在尝试编写一个python脚本,创建一个zip文件,然后将其上传(FTP)到服务器。但是,一旦我创建了zip文件(并关闭它),我就会得到一个
[Errno 2]没有这样的文件或目录:“2014.3.20.17.3.42。测试员.zip'
但是,我可以在z.close之后设置断点,并浏览(不是通过python代码)到该位置,并且该文件存在并且可以访问。你知道吗
据我所知,我唯一要做的就是关闭zip文件。在z.close()之后,我还需要做些什么,以便在代码中可以访问它吗?你知道吗
如果有关系的话,我现在正在使用Python2.6。你知道吗
代码:
import datetime
import os
from zipfile import ZipFile
from zipfile import ZipInfo
import zipfile
Directory = r"C:\Users\myUserAcct\Documents\output"
theDateTime = datetime.datetime.now()
theDateTimeFormatted = str(theDateTime.year) + '.' + str(theDateTime.month) + '.' + str(theDateTime.day) + '.' + str(theDateTime.hour) + '.' + str(theDateTime.minute) + '.' + str(theDateTime.second)
theZipFileName = theDateTimeFormatted + '.tester.zip'
z = ZipFile(theZipFileName,'w', zipfile.ZIP_DEFLATED)
os.chdir(Directory)
filelist = os.listdir(".")
for f in filelist:
z.write(f)
z.close()
tehFile = open(theZipFileName,'rb')
# Then i will upload (FTP) this file
tehFile.close()
在生成
ZipFile
实例之后,您正在执行os.chdir(Directory)
。在创建实例之前更改目录,它应该可以工作。你知道吗相关问题 更多 >
编程相关推荐