[AccessD] Unzip Files

DWUTKA at marlow.com DWUTKA at marlow.com
Thu Apr 28 09:59:36 CDT 2005


I don't know, I rarely use other people's code now, and so I prefer not to
post someone else's work.  You didn't include the comments I have in my
module, which denote the original author.

Drew

-----Original Message-----
From: Gustav Brock [mailto:Gustav at cactus.dk]
Sent: Thursday, April 28, 2005 9:49 AM
To: accessd at databaseadvisors.com
Subject: RE: [AccessD] Unzip Files


Hi Drew

Since when have you turned into chicken mode?
Here's the module:

Option Compare Database
Option Explicit

Private Const SYNCHRONIZE = &H100000
                                                
' Wait forever.
Private Const INFINITE = &HFFFF
' The state of the specified object is signaled.
Private Const WAIT_OBJECT_0 = 0
' The time-out interval elapsed and the object's state is
nonsignaled.
Private Const WAIT_TIMEOUT = &H102

Private Declare Function OpenProcess Lib "KERNEL32" ( _
  ByVal dwDesiredAccess As Long, _
  ByVal bInheritHandle As Long, _
  ByVal dwProcessId As Long) _
  As Long

Private Declare Function WaitForSingleObject Lib "KERNEL32" ( _
  ByVal hHandle As Long, _
  ByVal dwMilliseconds As Long) _
  As Long

Private Declare Function CloseHandle Lib "KERNEL32" ( _
  ByVal hObject As Long) _
  As Long
  
' The WaitForSingleObject function returns when one of the following
occurs:
' - The specified object is in the signaled state.
' - The time-out interval elapses.
'
' The dwMilliseconds parameter specifies the time-out interval, in
milliseconds.
' The function returns if the interval elapses, even if the object's
state is
' nonsignaled. If dwMilliseconds is zero, the function tests the
object's state
' and returns immediately. If dwMilliseconds is INFINITE, the
function's time-out
' interval never elapses.
'
' This example waits an INFINITE amount of time for the process to end.
As a
' result this process will be frozen until the shelled process
terminates. The
' down side is that if the shelled process hangs, so will this one.
'
' A better approach is to wait a specific amount of time. Once the
time-out
' interval expires, test the return value. If it is WAIT_TIMEOUT, the
process
' is still not signaled. Then you can either wait again or continue
with your
' processing.
'
' DOS Applications:
' Waiting for a DOS application is tricky because the DOS window never
goes
' away when the application is done. To get around this, prefix the app
that
' you are shelling to with "command.com /c".
'
' For example: lngPid = Shell("command.com /c " & strCommand.Text,
vbNormalFocus)

Function ShellWait( _
  ByVal strCommand As String) _
  As Boolean

  Dim lngPid      As Long
  Dim lngHnd      As Long
  Dim lngReturn   As Long
  Dim booSuccess  As Boolean
  
  If Len(Trim$(strCommand)) > 0 Then
    lngPid = Shell(strCommand, vbNormalFocus)
    If lngPid <> 0 Then
      ' Get a handle to the shelled process.
      lngHnd = OpenProcess(SYNCHRONIZE, 0, lngPid)
      ' If successful, wait for the application to end and close the
handle.
      If lngHnd <> 0 Then
        lngReturn = WaitForSingleObject(lngHnd, INFINITE)
        CloseHandle (lngHnd)
        booSuccess = True
      End If
      MsgBox "Just terminated.", vbInformation, "Shelled Application"
    End If
  End If
  
  ShellWait = booSuccess

End Function


>>> DWUTKA at marlow.com 04/28 4:37 pm >>>
It's a function called ShellWait.  It's code available on the net
(should
show up with a google search), I'd post it here, but I don't think we
are
supposed to post other people's code.

Drew

-----Original Message-----
From: Hale, Jim [mailto:Jim.Hale at fleetpride.com] 
Sent: Thursday, April 28, 2005 8:58 AM
To: 'Access Developers discussion and problem solving'
Subject: RE: [AccessD] Unzip Files


<Then I would shell (and wait) to a command line>
how do you pause Access so that it waits until the process is finished?
I
have a process that creates and runs cmd and bat files and then
destroys
them. I have to pause Access so that the files are run before Access
kills
them. My current method is a kludge. In Excel I use the Wait function.
Is
there an analogous function in Access? TIA
Jim Hale

-----Original Message-----
From: DWUTKA at marlow.com [mailto:DWUTKA at marlow.com] 
Sent: Wednesday, April 27, 2005 5:18 PM
To: accessd at databaseadvisors.com 
Subject: RE: [AccessD] Unzip Files


Sorry for the delay.....but I've been a little swamped during this
thread.
Ironically, I am rebuilding an application that 'auto' extracts files
from
zips.  It's probably more complex then what you are looking for though.


I host a realty website (remax realtors).  It has a ton of properties,
which
are updated regularly.  The updates are posted to an FTP site, and are
zipped.  The zip files contain both delimited text files with the
property
information, and .jpg files with images for the property.

My original application used the INet control in VB, to download the
files
to a directory.  Then I would shell (and wait) to a command line that
unzipped all of the files to that folder.  That was actually pretty
easy to
do. The REAL fun part was then to extract all of the information from
the
unzipped text files, update the database, and then sort all the
pictures
(and create thumbnails for them).  The only trick on the first part was
the
unzipping.  I found and Add-on for WinZip, which works perfectly, but
the
only catch is that you have to have a registered version of WinZip for
it to
truly work automated.  If it's not registered, the command line prompts
you
for things...which is a little quirky for an 'automated' system.  So I
splurged on the $29 to register WinZip.  It was money well spent.  The
command line works wonderfully, and better yet, the registered version
of
WinZip has a lot of neat features to use.

The reason I am rebuilding this application, is because I spent the
last few
weeks rebuilding my home network.  Now that I have everything setup at
home
(almost), I want to improve this process.  It's downloading about 1.5
gigs
worth of zip files, which even over my 3 megabit connection, takes a
while.
Then it unzips them (which can take just as long, or longer), then it
runs
the 'update' process.  During the download, doing anything on my own
crawls
to dialup speed sometimes.  During the rest, that server is pretty tied
up.
I decided to change the download/unzip process, and also modify the
update
process, so that my customers will be able to track what has been
updated.
In the download/unzip phase, I was using the INet control, which is
quirky,
and the way I had it setup, I knew what file was downloading, but not
how
big it was, or how fast it was downloading, and I couldn't pause it,
only
kill the whole process.  So the new process (which I have the dl/unzip
phase
done, working on the new update process) downloads everything using
API
calls, and not only shows the file size, but how much has been
downloaded
and even has pause and cancel buttons. (Can't pause it forever, because
the
FTP site will time out, but I'm going to fix that too.....).  So now,
if I
want to use the net at high speeds, when this thing is running, I can
just
go to the server, and pause the process.  I also made a modification to
the
zip process.  Instead of one big unzip '*.zip' command line, I have the
VB
program start a new thread, and that thread starts runs the unzip
process
for one zip file.  Works like a charm.  (It's all event driven too, so
when
the last zip thread is done, it raises an event the main process can
use to
launch the update process).

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list