Zipping and emailing from NAV 3.7

MatStephensSandAMatStephensSandA Member Posts: 74
Hi All.

I (like many before me) have to zip a bunch of files then email them to a customer .
I have read many strings in the forum on the subject and the blow code (kind of) works for me
// Vars
IntegerValue	Integer		
i	Integer		
Shell32	Automation	'Microsoft Shell Controls And Automation'.Shell	
SrcFolder	Automation	'Microsoft Shell Controls And Automation'.Folder	
DstFolder	Automation	'Microsoft Shell Controls And Automation'.Folder	
SrcItems	Automation	'Microsoft Shell Controls And Automation'.FolderItems3	
TextFile	File		
ZipFileName	Text		1024
SourceFolderName	Text		1024
//Code
ZipFileName := 'c:\test.zip';
SourceFolderName := 'c:\test';
TextFile.CREATE(ZipFileName); 
TextFile.TEXTMODE(FALSE); 
IntegerValue:=101010256; 
TextFile.WRITE(IntegerValue); 
IntegerValue:=0; 
FOR i:=1 TO 9 DO 
  TextFile.WRITE(IntegerValue); 
TextFile.CLOSE; 
if isclear(Shell32) then
  CREATE(Shell32);

SrcFolder:=Shell32.NameSpace(SourceFolderName); 
DstFolder:=Shell32.NameSpace(ZipFileName); 
SrcItems:=SrcFolder.Items; 
DstFolder.CopyHere(SrcItems); 

but im an inquisitive so and so therefore i have a few questions and in addition would like to take the process to another level of complexity

first my questions
1.What is the relevance of
IntegerValue:=101010256;
2.Whats the point of the loop?
FOR i:=1 TO 9 DO

Now for the complexity
If (as i suspect) the loop is simply a filler of time to allow for the zip process to work, then how would I develop the code to allow for a variable number of files. For example I am trying to compress our Proof Of Delivery .tif files per customer and Email them to that customer. One customer folder might contain 1800 documents the next may only hold 1 so putting a static loop of 9 may delay the process where it doesnt need to be delayed equally might not delay the process enough

A further complexity issue relates to the email section of the process. Due to email poliocy, the biggest email attachment i can send is 3 Meg. So how would i split this zipping process to create a new zip file each time the file exceeds the 3MB size limit??

thanks in advance


PS. we have tried to use the SHELL command but failed spectacularly.
M@
I have seen the future and it's egg shaped.

Comments

  • FDickschatFDickschat Member Posts: 380
    The Integer value and the loop create a zip file with a correct zip header. So after creating this you can open the file with a zip tool (explorer, 7zip,...).

    I have no idea why someone would do it like this. :shock:

    What I would do:
    - Get 7zip. It's free and very reliable, exists for x32 and x64. Download the tool and additionally the command line tool.
    - Look through the help of 7zip how to create a zip by running 7zip with parameters. There are parameters which will delete a file after it has been zipped. You can even set a parameter so that 7zip generates files split by 3Megs

    In NAV (I assume all the files to zip are in 1 folder):
    - If you want to zip everything in that folder just use 7zip on the folder with *.*. If you want to skip some files use the virtual table File (2000000022). Set filters for your folder and loop through the files using the add option in 7zip. Let 7zip create the new files in another folder. Make sure it is empty before running the process
    - When 7zip is done search in table File for the newly created zips and count them. You need to generate 1 mail per file.

    Remark:
    When using table File you need to use a local variable for that table and to place the code inside a function which you clear before running it again. Otherwise NAV will show you old cached contents of a folder which no longer exist http://www.mibuso.com/forum/viewtopic.php?f=23&t=37663.

    [Edit]
    I usually first move all files I find in a folder (that is usually a folder where an automated process or a user writes files to) to a second, empty folder and run the processing (import or zip) from there. Usually I will not use 7zip to delete the files but will move them after the zipping process to an archive folder where they will be deleted after some time. But this depends on your level of necessary security.
    Frank Dickschat
    FD Consulting
Sign In or Register to comment.