EDIT : When using the library version 0.4 and higher, you can choose whether to include subdirectories. For instance:.
Create Zip From Files In Directory ../xml/komplett/ no_sub_folders.zip Create Zip From Files In Directory ../xml/komplett/ dir_and_sub_folders.zip sub_directories=${true}
The keyword for creating tar is a little different - by default it includes files in subdirectories, and now you have the option not:
Create Tar From Files In Directory ../xml/komplett/ dir_and_sub_folders.tar Create Tar From Files In Directory ../xml/komplett/ no_sub_folders.tar sub_directories=${false}
The default values ββof sub_directories are based on pre-existing behavior, and not on breaking existing customs in test cases.
Original answer, for versions <0.4:
If you want to fix the library, this code should do:
zip = zipfile.ZipFile(filename, "w") for path, _, files in os.walk(directory): for name in files: file_to_archive = os.path.join(path, name)
Edit: saves the subdirectory structure for in - subdirectory files. The generated file is located with the top-level target directory and all its subdirectories under it (unlike an archive that saves the full path to the target directory)
arcname controls the arguments , which is the name of the file stored in the archive - and through line 7, we save the relative directory plus the file name.
Always use os.path.join , because it automatically takes care of differences in different file systems (ntfs / linux / etc).
If the final solution works for you, do not forget to offer the patch to the library owner - return it to the community :)