question regarding unzipping a file

G

Gary Keramidas

i'm using the shell command to unzip a file. problem is, i need to know when the
file is accessible.
using a loop such as:

Do Until Dir(fpath & "*.dat") <> ""
Loop

doesn't really work, because the file exists, but it's not completely unzipped
and is inaccessible. i could use a wait, but every pc is different and i don't
want to use some arbitrary number of seconds.

so, what's the best way to tell when the unzipping procedure is complete?
 
R

Rick Rothstein

This procedure might work for you...

Paste these lines in the (General)(Declarations) section of the code window
where the Shell command is being called from (or remove the Private keywords
and put them in a BAS module if more than one form will use them):

Private Declare Function OpenProcess _
Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle _
Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject _
Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Call your Shell command in this form with the appropriate Shell arguments
placed in the parentheses:

PID = Shell( <<Put Shell Arguments Here>> )

And finally, paste the following IMMEDIATELY after the PID=Shell statement
above (making sure to handle the possible error where indicated; i.e. stop
the code from falling through to your other commands if the Shell failed):

If PID = 0 Then
'
' Handle Error, Shell Didn't Work
'
Else
hProcess = OpenProcess(&H100000, True, PID)
WaitForSingleObject hProcess, -1
CloseHandle hProcess
End If
'
' Rest of your code goes here
'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top