Have you ever had to generate a zip file and then send it via mail / ftp / … maybe starting from a folder of the IFS populated with files?
Here is a method to do this using the PASE shell embedded in a CLLE program.
Index
First of all it is better to create a workbook inside the / tmp (present by default on all releases) or inside one’s home (ex. / Home / myUsrPrf).
CRTDIR DIR ('/ home / PETRIS / zipTemp')
In order to get the list of files contained in an IFS folder it is possible to launch the ls command
CHGVAR VAR (& QSHCMD) VALUE ('cd myFolderIFS; ls *. *> /Home/PETRIS/zipTemp/listaFilesDaZippare.txt') QSH CMD (& QSHCMD)
Once the list of files is obtained, in order to manage a reading cycle we copy the text into a physical file
// Creating source files CRTSRCPF FILE (QTEMP / SRC) RCDLEN (212) MBR (* FILE) // Copy IFS txt file to source file CPYFRMSTMF FROMSTMF ('/ home / PETRIS / zipTemp / elencoFilesDaZippare.txt') TOMBR ('/ QSYS.LIB / QTEMP.LIB / SRC.FILE / SRC.MBR') MBROPT (* REPLACE) ENDLINFMT (* LF) // Copy from source file to physical file (previously created) CPYF FROMFILE (QTEMP / SRC) TOFILE (QTEMP / MYFLATFILE) MBROPT (* REPLACE) FMTOPT (* CVTSRC) ERRLVL (* NOMAX)
At this point we proceed to create the zip file (only the first time) and insert each of the files in the list
CHGVAR VAR (& NVOLTE) VALUE (1)
CYCLE: RCVF
MONMSG MSGID (CPF0000) EXEC (GOTO CMDLBL (FINECICLO))
IF COND (& NVOLTE * EQ 1) THEN (DO)
/ * & MYFLATFLD = field of the MYFLATFILE * / physical file
CHGVAR VAR (& QSHCMD) VALUE ('cd myFolderIFS; ajar -cM /home/PETRIS/myZipFile.zip' * CAT & MYFLATFLD)
QSH CMD (& QSHCMD)
CHGVAR VAR (& NVOLTE) VALUE (0)
ENDDO
ELSE CMD (DO)
CHGVAR VAR (& QSHCMD) VALUE ('cd myFolderIFS; ajar -aM /home/PETRIS/myZipFile.zip' * CAT & MYFLATFLD)
QSH CMD (& QSHCMD)
ENDDO
GOTO CMDLBL (CYCLE)
END OF THE CYCLE:
Every time the operating system inserts a file into the zip it disappears from the IFS (in practice the file is moved from the folder to the archive)
At this point all that remains is to delete the files and the temporary folder
DLTF FILE (QTEMP / SRC) DLTF FILE (QTEMP / MYFLATFILE) DEL OBJLNK ('/ home / PETRIS / zipTemp / listaFilesDaZippare.txt') RMVDIR DIR ('/ home / PETRIS / zipTemp')
To carry out the opposite operation it is sufficient to use the same command with different parameter
cd /
home / PETRIS / zipTemp; ajar -x /home/PETRIS/myZipFile.zip
at this point the system will have extracted the contents of myZipFile.zip in the zipTemp folder
We are pleased to receive and share this "tip & trick" from Patrick Rizzi, which introduces a technique that allows…
I take inspiration from a response by Michael Mayer on the Midrange.com mailing lists to someone who asked how to…
Businesses are increasingly seeking tools to enhance efficiency, collaboration, and resource management. Enterprise Resource Planning (ERP) systems provide a comprehensive…
Early April saw the release of the "Spring Version" of ACS Access Client Solution, version 1.1.9.5 Interesting new features especially…
If the packed agenda of sessions at Common Europe Congress 2024, June 3-6 Milan, wasn't enough for you, here's another…
Debugging functions with Visual Studio Code have been available for some time but this new version 2.10.0 simplifies the handling…