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
How I detect a file is ready to be attached to an e-mail?
Moderators: JRL, Dorian (MJT support)
How I detect a file is ready to be attached to an e-mail?
Thanks,
Salvador Hernandez
Salvador Hernandez
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]
[email protected]
How to detecte a file is ready for email
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
.
.
.
.
.
.
Label>CHECK_FOR_FILE
IfFileExists>FILENAME,ZIP_COMPLETE
Wait>5.0
GoTo>CHECK_FOR_FILE
Label>ZIP_COMPLETE
.
.
.
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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!
Bob
A humble man and PROUD of it!
Solution with VBScript
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
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
Salvador Hernandez