使用Robot Framework,我试图用一个文件和三个包含文件的子目录压缩目录。我正在使用ArchiveLibrary和关键字“从目录中的文件创建邮编”。结果是一个压缩目录包含顶部目录中的一个文件和三个空的子文件夹。与Robot Framework中的子目录的Zip目录
如何调整库以便子文件夹的内容也包含在内?
这是怎样的关键字最初定义:
def create_zip_from_files_in_directory(self, directory, filename):
''' Take all files in a directory and create a zip package from them
`directory` Path to the directory that holds our files
`filename` Path to our destination ZIP package.
'''
if not directory.endswith("/"):
directory = directory + "/"
zip = zipfile.ZipFile(filename, "w")
files = os.listdir(directory)
for name in files:
zip.write(directory + name, arcname=name)
zip.close()
Link到完整的图书馆。
我一直在尝试os.walk,但没有成功。
如何关键字在.robot文件中使用:
Zip xml file
${zipfilename}= set variable komplett.zip
Create zip from Files in directory ../xml/komplett/ ${zipfilename}
如果它的确与众不同,我真的只需要解决这个特定的情况下,不是一般的一个,这意味着我不介意在每个目录中输入路径,然后以某种方式加入,我只是不明白如何去做... 另外,我使用PyCharm作为编辑器,而不是RIDE。
谢谢!这使我更加靠近了一点,但并没有像预期的那样工作。现在我得到所有文件,但是子目录被删除。 为了使机器人脚本工作,我需要保持目录的确切结构(OT:因为实际的测试是通过验证脚本运行压缩目录,其中测试变体是要更改XML文件中的数据放置在压缩目录中) 子目录和结构是否也包含在内? – Sabotchick
那么,“这会教我发布无线运行”:) JK,编辑了包含该部分的答案 - 另外还清理了一些并非真正需要的代码。 HTH – Todor
太棒了,就是我想要的!谢谢! :) – Sabotchick