Knowing when done zipping a file... 
Author Message
 Knowing when done zipping a file...

I have a backup program that I am writing in Visual Basic. I would like
to know if there is a way in which I can tell when I am done zipping up
the files using PKZIP. Right now I am using Shell to call a DOS batch
file to pkzip the files. But how d I know when it is done? Or can anyone
suggest a better way?

Thanks a lot, I really appreciate this.

Sanju Abraham



Tue, 11 Jul 2000 03:00:00 GMT  
 Knowing when done zipping a file...

I'd do something like this:

Sub ZipThroughBatch()
    dim X as long
    Const PASS_FILE = "C:\ZIP_GOOD.FLG"
    Const FAIL_FILE = "C:\ZIP_FAIL.FLG"
    Const BATCH_FILE = "C:\ZIPIT.BAT"
    On Error Resume Next
    Kill PASS_FILE
    Kill FAIL_FILE
    On Error Goto ErrorHandler
    X = Shell(BATCH_FILE + " " + PASS_FILE + " " + FAIL_FILE,vbNormalFocus)

    'You have to write/have a FileExists() function and you should probably
have a timeout
    'check, too, otherwise this could end up in an endless loop
    While Not (FileExists(PASS_FILE) OR FileExists(FAIL_FILE))
    Wend

    'You need a way to kill the "Finished" DOS operation now, too.  I forget
how to do this but it is
    'documented in many places.

    If FileExists(PASS_FILE) then
        MsgBox "Backup Successful!!!"
    elseif FileExist(FAIL_FILE) then
        MsgBox "Backup Failed!!!"
    else
        MsgBox "Backup timedout"
    End if
ExitRoutine:
    Exit Sub
ErrorHandler:
    MsgBox "Error in ZipThroughBatch: " & Error
    Resume ExitRoutine
End Sub


PKZIP {etc, etc}
if errorlevel 1 goto ZIPFAILED
ECHO This is a flag file indicating that PKZIP completed successfully>%1
goto END
:ZIPFAILED
echo This is a flag file indicating that PKZIP failed>%2
echo Zip Failed!!!
:END
-----ZIPIT.BAT ends

Whenever running DOS Batch files from the Shell() command I'd always use
this flag file idea to indicate the status of the batch file.

Quote:

> I have a backup program that I am writing in Visual Basic. I would like
> to know if there is a way in which I can tell when I am done zipping up
> the files using PKZIP. Right now I am using Shell to call a DOS batch
> file to pkzip the files. But how d I know when it is done? Or can anyone
> suggest a better way?

> Thanks a lot, I really appreciate this.

> Sanju Abraham


--
"Are short people the last ones to know when it rains?"

Paul Johnston   Occasional Percussion staff member,




Thu, 13 Jul 2000 03:00:00 GMT  
 Knowing when done zipping a file...

How about making a PIF file for the program you are shelling, enabling
it to Close After Finishing. That way you may even call PKZIP itself and
supply the commandline parameters without the use of a batch file.

Hope it helps...

Niq



Mon, 17 Jul 2000 03:00:00 GMT  
 Knowing when done zipping a file...

I had the same question and found the answer in an article in Dejanews.
Here's an overview:

Shell the command interpreter with the "/C" parameter. The "/C" parameter
tells the command environment to close the window after the command line
has finished execution.

Here's sample code for a Command Button Click event:

Private Sub Command1_Click()
   Dim szCmdIntpr       As String
   Dim lRetVal          As Long
   Dim sFileName        As String
   Dim iFileNumber      As Integer
   Dim sOut     As String
   Const szCmdLine$ = "C:\WINDOWS\MYUNZIP.BAT"
   '
   If(Instr(1,Dir$("C:\WINDOWS\FLAG.TXT"),("FLAG.TXT")) > 0 Then
        ' Flag File exists, delete it
        Kill "C:\WINDOWS\FLAG.TXT")
   End If
   '
   If(Instr(1,Dir$("C:\WINDOWS\MYUNZIP.BAT"),("MYUNZIP.BAT")) > 0 Then
        ' Unzip Batch File exists, delete it
        Kill "C:\WINDOWS\MYUNZIP.BAT")
   End If
   '
   ' Create unzip batch file
   iFileNumber = FreeFile
   Open "C:\WINDOWS\MYUNZIP.BAT" For Output As #iFileNumber
   sOut = "C:"
   Write #iFileNumber, sOut
   sOut = "CD\WINDOWS\TEMP"
   Write #iFileNumber, sOut
   sOut = "PKUNZIP MYZIP.ZIP"
   Write #iFileNumber, sOut
   sOut = "CD\WINDOWS"
   Write #iFileNumber, sOut
   sOut = "DEL FLAG.TXT"
   Close #iFileNumber
   '
   DoEvents
   '
   ' Create flag file
   iFileNumber = FreeFile
   Open "C:\WINDOWS\FLAG.TXT" For Output As #iFileNumber
   sOut = "THIS IS A FLAG FILE"
   Write #iFileNumber, sOut
   Close #iFileNumber
   '
   szCmdIntpr = Environ$("COMSPEC")
   ' The Chr(32) adds a space between the command line arguments
   szCmdIntpr = szCmdIntpr & Chr(32) & "/C"
   lRetVal = Shell(szCmdIntpr & Chr(32) & szCmdLine)
   Do While Instr(1, Dir$("C:\WINDOWS\FLAG.TXT"),"FLAG.TXT) > 0
        ' The last command in the batch file will delete the FLAG.TXT file only
        ' after the pkunzip is complete
        DoEvents
        Sleep(500)      ' This is an API function, 500 = 500 ms
   Loop
   '
   ' Unzip Batch File exists, delete it
   Kill "C:\WINDOWS\MYUNZIP.BAT")
   '
   MsgBox "Unzip is complete",vbOkOnly,"Unzip Complete"
   DoEvents
   '
End Sub
Hope this helps,
BJ



Quote:
> How about making a PIF file for the program you are shelling, enabling
> it to Close After Finishing. That way you may even call PKZIP itself and
> supply the commandline parameters without the use of a batch file.

> Hope it helps...

> Niq



Wed, 19 Jul 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Reading files from a zip file (Just reading the filenames, not unzipping or zipping)

2. CGI32.ZIP Using VB to write CGI files - cgi32.zip (1/1)

3. How to knowing when a query is done

4. I know someone has done this before...

5. AnyOne knows How It can Be Done?

6. AnyOne knows How It can Be Done?

7. How to know when Print Spooler is done?

8. Please Help How does the program know when the Music is done

9. VBA to dump zip file contents to a file

10. How see file names inside zip files

11. Help: Creating Zip-File and Encrypted File

12. Accessing Files in a .ZIP File

 

 
Powered by phpBB® Forum Software