Re: GETFILE() Inside .Zip files?



Thank you very much, Roger. It's gonna take me a while to digest and
work with this (I might even learn something too! <g>.
Steve


On Tue, 28 Aug 2007 05:54:43 +0930, "Roger Ansell"
<notmy@xxxxxxxxxxxxxxxxxxxx> wrote:

"Steve Meyerson" <stevemeyerson@xxxxxxx> wrote

Looks like a good approach, Roger, thanks. I tried the code on a small
zip file with 2 files inside. Both files were copied ok. Now all I
have to do is figure out how to copy selectively from a list of files
and folders inside the zip file.

Sure, that takes a bit more work. I've got some sample code
to demo the Shell aspects of doing it which I've pasted below.
Basically what you need to do first is "scan" the zip file using the Shell
and place name, relative path and the actual Shell item object
of each file in an array. You can then use the array to populate a listbox,
grid or whatever so the user can make selections of what they want
to restore. Then you can process the array, again using the Shell
to extract and copy the selected files to their destination folders.

Of course it's trickier if there are subfolders involved but the code
below handles that too.

Is there a "tutorial" or something on using Shell and its capabilities
in VFP? I couldn't find one on Google or in the VFP doc.

Not that I'm aware of. I learned it by using Intellisense in the
command window and by referring to MSDN library for details of
each PEM. Actually better than a tutorial!

-Roger

*** Code ****
Local loShell As "Shell.Application"
lcDestFolder = "C:\temp\silly1"
loShell = CreateObject("Shell.Application")
loFolder = loShell.NameSpace("C:\temptest\Testclass")
loDestFolder = loShell.NameSpace(lcDestFolder)

loItems = loFolder.Items
For Each loItem In loItems
If loItem.Name = "New WinZip File.zip"
loZip = loItem
Exit
EndIf
Next

loZipFldr = loZip.GetFolder

* Create an array to hold the contents
* of the Zip for use in UI and later.
Dimension laZipItems(1,3)

*Fill the array (see Function below)
ParseFolder(loZipFldr,@laZipItems)

lnRows = Alen(laZipItems,1) - 1
Dimension laZipItems(lnRows,3)

* At this point you'd allow the user to select
* which files to extract & restore
* Just for the sake of illustration
* we'll just copy every other file in the zip

For i = 1 to lnRows
If Mod(i,2) = 0
If ! Empty(laZipItems(i,2))
lcDest = Addbs(lcDestFolder) + laZipItems(i,2)
If ! Directory(lcDest)
Md (lcDest)
EndIf
loDest = oShell.Namespace(lcDest)
loDest.CopyHere(laZipItems(i,3))
Else
loDestFolder.CopyHere(laZipItems(i,3))
EndIf
EndIf
Next

*****************************************************
Procedure ParseFolder
* Recursively parses the zip to include all subfolders
* and fills the array with file details and objects.
*********************
Lparameters lpoFolder, lpaZipItems
Local loItems,loItem,lnRows, loFolder, lcPath
loItems = lpoFolder.Items
For Each loItem in loItems
If loItem.IsFolder && if it's a folder
loFolder = loItem.GetFolder
ParseFolder(loFolder,@lpaZipItems)
Else
lcPath = loItem.Path
lnRows = Alen(lpaZipItems,1)
lpaZipItems(lnRows,1) = loItem.Name
* Note the CHRTRAN in the next line
lpaZipItems(lnRows,2) = Chrtran(JustPath(loItem.Path),"/","\")
lpaZipItems(lnRows,3) = loItem
Dimension lpaZipItems(Alen(lpaZipItems,1)+1,3)
EndIf
Next

EndFunc

*** End code ***





Steve

On Mon, 27 Aug 2007 05:55:05 +0930, "Roger Ansell"
<notmy@xxxxxxxxxxxxxxxxxxxx> wrote:

Hi,

There is a way which doesn't rely on third-party tools and
you can use VFP's standard GetFile dialog.
OK, your user gets the zip file name he wants to extract from
GetFile(). You then extract the path and file name to
separate variables, eg:

lcFile = GetFile()
lcPath = JustPath(lcFile)
lcZipFile = JustFname(lcFile)

* Let's specify the destination path
* so your user doesn't have to intervene:

lcDestPath = "C:\MyApp"

* Now comes the tricky part <s>

Local loShell As "Shell.Application"
loShell = CreateObject("Shell.Application")
* Get a folder object for the source path:
loFolder = loShell.NameSpace(lcPath)
* Get a collection of the files in the folder:
loItems = loFolder.Items
* Now let's find the zip file we want:
For Each loItem In loItems
If Upper(loItem.Name) == Upper(lcZipFile)
* We've found the target zip file
loZip = loItem
Exit
EndIf
Next

* Return a folder object for the zip file
loZipFldr = loZip.GetFolder
* Get a collection of all the files in the zip
loZipItems = loZipFldr.Items
* Specify the destination folder object
loDestFolder = loShell.NameSpace(lcDestPath)
* Copy from the zip to the destination
loDestFolder.CopyHere(loZipItems)

All done!

HTH

-Roger

BTW there's an additional optional parameter
to the CopyHere() method which allows you to
handle how the extraction occurs.
These values are additive:
4 Do not display a progress dialog box.
8 Give the file being operated on a new name in a move, copy,
or rename operation if a file with the target name already
exists. 16 Respond with "Yes to All" for any dialog box that is
displayed. 64 Preserve undo information, if possible.
128 Perform the operation on files only if a wildcard file name
(*.*) is specified. 256 Display a progress dialog box but do not
show the file names. 512 Do not confirm the creation of a new
directory if the operation requires one to be created. 1024 Do not
display a user interface if an error occurs. 2048 Version 4.71. Do
not copy the security attributes of the file. 4096 Only operate in
the local directory. Don't operate recursively into subdirectories.
9182 Version 5.0. Do not copy connected files as a group. Only copy
the specified files.





"Steve Meyerson" <stevemeyerson@xxxxxxx> wrote in message
news:6j01d3lnm449p6cuisk70lan75qecm3kl8@xxxxxxxxxx
The GETFILE() dialog window in VFP8 & 9 closes when I select a file
with the .zip extension and the function returns the path and name
of the .zip file.

Is there a way in VFP to display and select a file inside the .zip
file, as in Windows Explorer?

TIA

Steve M.


.



Relevant Pages

  • Re: GETFILE() Inside .Zip files?
    ... You can then use the array to populate a listbox, ... For Each loItem In loItems ... Get a folder object for the source path: ... Do not display a progress dialog box. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: GETFILE() Inside .Zip files?
    ... Get a folder object for the source path: ... For Each loItem In loItems ... Specify the destination folder object ... 256 Display a progress dialog box but do not show the file names. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: GETFILE() Inside .Zip files?
    ... you can use VFP's standard GetFile dialog. ... Get a folder object for the source path: ... For Each loItem In loItems ... 256 Display a progress dialog box but do not show the file names. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: GETFILE() Inside .Zip files?
    ... you can use VFP's standard GetFile dialog. ... Get a folder object for the source path: ... For Each loItem In loItems ... 256 Display a progress dialog box but do not show the file names. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Detecting PDF files in a folder and sorting them by date
    ... > I am about to write an application that will display all pdf files ... > in a folder and display them by file name in order of date. ... $names = array(); ...
    (comp.lang.php)

Quantcast