03-24-2009 3:19 PM
Hi all,
is it possible to define folders in a zip file which is created with the class cl_abap_zip? For the case it will not work: is there any other possibility to create a zip file with folders in abap?
Thanks in advance.
Michael
03-25-2009 9:12 AM
Hello,
thanks four your answers. A solution as described by Mr. Brunneder is a workaround but doesn't fit for my requirements.
The solution from Mr. Vadali was not ok because it doesn't fit to my question: I do not want to add files and folders from a local directory of a client to a zip archive.
The requirement is to create a zip archive with folders to sort some type of files in an abap source code directly.
Best regards.
Michael
03-25-2009 6:25 AM
Hi!
I also don't know a possibility to create folders with class cl_abap_zip. However, you can use sub-zip-archives in order to structure your (top-)zip-archive since method ADD accepts type xsequence which is compatible to xstring from method LOAD or SAVE, e.g.:
* open (top-)zip-archive
CALL METHOD lo_zip->load
EXPORTING
zip = lv_zip_file_head
EXCEPTIONS
zip_parse_error = 1
OTHERS = 2.
...
* create sub-zip-archives which contain the files you would assign to a folder
...
* add sub-zip-archive to top-zip-archive
CALL METHOD lo_zip->add
EXPORTING
name = lv_zip_filename
content = lv_zip_file.
* save zip-archive
CALL METHOD lo_zip->save
RECEIVING
zip = ev_zip_file.
I hope I was able to help you!
Regards
Wolfgang
03-25-2009 9:12 AM
Hello,
thanks four your answers. A solution as described by Mr. Brunneder is a workaround but doesn't fit for my requirements.
The solution from Mr. Vadali was not ok because it doesn't fit to my question: I do not want to add files and folders from a local directory of a client to a zip archive.
The requirement is to create a zip archive with folders to sort some type of files in an abap source code directly.
Best regards.
Michael
01-18-2012 12:18 PM
Hi,
creating folders in a ZIP file is rather easy. VERY easy.
If you read the ZIP file format definition, you will notice that subfolders are simply created based on the file names in the ZIP file.
So if you do a cl_abap_zip->add( ) and give 'subfolder/filename' and content, the file will be located in a subfolder named 'subfolder' in the ZIP file.
So if you want to pack e.g. a full tree of files, you can recursively iterate the subdirectories and use add( ) on the same cl_Abap_zip object with the correct filename consisting of relative path + delimiter (always forward slash '/') + filename.
Hope that helps.
Cheers,
Thomas
Edited by: THOMAS HERZOG on Jan 18, 2012 1:19 PM