How I detect a file is ready to be attached to an e-mail?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
shamigc
Junior Coder
Posts: 37
Joined: Wed Oct 22, 2003 11:38 am
Location: Monterrey, Mexico

How I detect a file is ready to be attached to an e-mail?

Post by shamigc » Thu Sep 09, 2004 11:52 am

Hi,

I developed a subroutine to zip files, and I use it to attach those zipped files to an e-mail message. The problem I have with this soubroutine is that I do not know how to detect when the winzip program finished zipping the file, so it can be attached to the e-mail. Until now I implemented a "Loop-Until" and "For-Next" to wait some time so the file is ready to be attached, but I have to increase/decrease the "For-Next" deppending on how fast/slow is a PC, Could you please help me to solve this problem, so the soubroutine detects when the zip file is ready to be attached without dependind on the PC speed?

Here is the code:
Sub ZipCompress(ArchivoZip,ListaAZippear)
Comando = "C:\Archivos de programa\WinZip\WINZIP32.EXE -min -a -ex " + ArchivoZip + " @" + ListaAZippear
Set oShell = createobject("WScript.Shell")
Set oProc = oShell.Exec(Comando)
Set fs = CreateObject("Scripting.FileSystemObject")
Do
Loop Until fs.FileExists(ArchivoZip)
For Contador = -1000000 To 1000000
Next
Set oShell = Nothing
Set oProc = Nothing
Set fs = Nothing
End Sub
Thanks,
Salvador Hernandez

Lumumba

Post by Lumumba » Thu Sep 09, 2004 12:43 pm

Something similar has been answered by Bob some time ago.
If you execute WinZip via the command line you could check if its window is still active or has colapsed/closed already.

Adios :wink:

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Sep 09, 2004 12:44 pm

Use the Winzip command line add on. Then you can use Run Program and set RP_WAIT to 1 so that the script won't continue until the zip has been created. You can then send the file by email.
MJT Net Support
[email protected]

mraftary

How to detecte a file is ready for email

Post by mraftary » Tue Sep 28, 2004 12:00 pm

Below is a simple GoTo loop that checks for the existance of the file every 5 seconds. Place it right after your zip code. The loop will continue until the file exists. Once the IF statement is true, the macro branchs to whatever action you wish. Replace FILENAME with your path and filename. The path and filename can also be assigned as a variable with a Let command at the beginning of the macro.
.
.
.
Label>CHECK_FOR_FILE
IfFileExists>FILENAME,ZIP_COMPLETE
Wait>5.0
GoTo>CHECK_FOR_FILE

Label>ZIP_COMPLETE
.
.
.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Sep 28, 2004 2:40 pm

A possible problem with using IfFileExists, is that the file may not yet be complete. Depending on how the file is created, it may exist at 0 bytes, and then grow as it is created. You may need to check the file size once you know it exists, and monitor it to see when it has stopped growing.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Lumumba

Post by Lumumba » Tue Sep 28, 2004 3:42 pm

I'm using 7zip. To run it from within a DOS box - and wait till this DOS box has closed, worked fine. Always.

shamigc
Junior Coder
Posts: 37
Joined: Wed Oct 22, 2003 11:38 am
Location: Monterrey, Mexico

Solution with VBScript

Post by shamigc » Thu Sep 30, 2004 10:26 am

I found a solution, taking into account that a file can not be copied until 'winzip' finished, and that you will get an error if you try to do it if 'winzip' has not finished. Thanks for your help. Here is the code, already tested:

Sub ZipCompress(ArchivoZip,ListaAZippear)
Temporal = Replace(ArchivoZip,".zip","1.zip")
Comando = "C:\Archivos de programa\WinZip\WINZIP32.EXE -min -a -ex " + ArchivoZip + " @" + ListaAZippear
Set oShell = createobject("WScript.Shell")
Set oProc = oShell.Exec(Comando)
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(Temporal) Then
fs.DeleteFile Temporal, True
End If
On Error Resume Next
Do
fs.CopyFile ArchivoZip, Temporal
Loop Until fs.FileExists(Temporal)
fs.DeleteFile Temporal, True
On Error Goto 0
Set oShell = Nothing
Set oProc = Nothing
Set fs = Nothing
End Sub
Thanks,
Salvador Hernandez

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts