GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Possible To Check For Folder/File in .ZIP File?

Hi,

I've been researching the Command Reference but have not found a solution to a problem I'm trying to solve. This is the situation:
[ul][li]I have a backup program that creates a backup file in .ZIP format but does not use the .ZIP extension;[/li]
[li]The "zip" backup file is compressed with a password;[/li]
[li]The "zip" backup file always contains 7 standard internal program files at the root, even if none of my data files was backed up (it is an incremental backup);[/li]
[li]When at least one of my data files has been backed up, it is created under the folder structure "Data", which is located in the root of the "zip" backup file;[/li]
[li]Even though the "zip" backup file is compressed with a password, in DOpus I can double-click on the "zip" backup file (e.g., rename or copy the file to .ZIP) and I will be presented with the root directory listing of the "zip" backup file (of course, if I try to open any file thereafter, I correctly get prompted for a password);[/li]
[li]What I'm trying to determine programmatically is if the "Data" folder exists in the root. Thus, if it exists, then it means that I have actual data files backed up; if it does not, then it means nothing was backed up;[/li]
[li]If nothing was backed up (i.e., the "Data" folder does not exist in the root of the "zip" backup file), then I want to delete that "zip" backup file.[/li][/ul]
Is it possible to write a script that achieves the above?

Thanks!

The following script button will do that. First, you'll need to go to Preferences / Zip & Other Archives / Zip Files and add the custom ZIP extension to the Zip Extensions field. This will make Opus treat those files like normal Zip files without having to rename them first.

Paste the following button into your toolbar (instructions here). You'll need to edit it to change the path to that of your backup file (the line that currently says arcFile = "C:\Temp\BackupArchive.zip").

<?xml version="1.0"?> <button backcol="none" display="both" textcol="none"> <label>Delete Empty Backup</label> <icon1>#newcommand</icon1> <function type="script"> <instruction>@script vbscript</instruction> <instruction>Option Explicit</instruction> <instruction /> <instruction>Dim arcFile, cmd</instruction> <instruction>arcFile = &quot;C:\Temp\BackupArchive.zip&quot;</instruction> <instruction /> <instruction>If DOpus.FSUtil.Exists(arcFile) Then</instruction> <instruction> If Not DOpus.FSUtil.Exists(arcFile &amp; &quot;\Data&quot;) Then</instruction> <instruction> DOpus.Create.Command.RunCommand &quot;Delete QUIET FILE &quot;&quot;&quot; &amp; arcFile &amp; &quot;&quot;</instruction> <instruction> End If</instruction> <instruction>End If</instruction> </function> </button>


Hi Jon,

Thanks for the prompt reply! But I get the following error:

Error at line 9, position 7
Object doesn't support this property or method: 'DOpus.Create' (0x800a01b6)

Never mind...I researched and found used DOpus.NewCommand instead and that worked!

But now to add some customization to loop through all "zip" files in the directory. Will post back shortly!

Thanks again for your help, Jon.

My new button really helps me out a lot because my backup program runs every 10 minutes and when there are no files to backup it still creates these "unnecessary" backup files which, in totality, end up consuming a lot of space.

DOpus is really, really awesome!!! :thumbsup:

Apologies, the DOpus.Create method was added in the 11.7.1 beta. Glad you got it working!

Does FSUtil fully support ZIP files? Can I ReadDir() into them and make use of OpenFile() to alter files within ZIP files directly?
The docs do not say so directly, but there are some hints and you obviously use it to "look" into a ZIP, didn't know that's possible. o)

Any folder you can open in a Lister (other than shell namespace extensions like Network) you can read with FSUtil. So archives, collections, libraries, even ftp in theory.

Ah ok! And in case I need look for special files in a zip, get them out of there to manipulate them and then put them back in, would you choose FSUtil for iterating over the content and the COPY command to get them out/back in?
Or would I better just extract the complete zip file to some tmp-folder, operate on the tmp-files with what I like and finally zip the complete folder.

There are not many files in those zips and they are quite small as well, I'm speaking about script packages actually (*.osp).

You might be able to use OpenFile to read files from a zip directly. I'm not sure if it will write to files as well. (If it does, it'll only work in Zip archives at the moment, and not 7z etc.)

But if you're going to be doing more than a few files, it's often quicker to extract the whole archive, do the work, then re-create the archive. Then all the archive overheads are only paid once, instead of once per file.

OTOH, with a small archive like a config backup, it probably won't make any difference either way, so go with whatever is easiest. I'd still go with extracting everything to a temp dir, as then you have a lot more tools to work with.

I think I'll go the full-extract way then, it seems to be more flexible for what I plan to do and probably prevents me from getting into the unexpected. o)
Thank you for your thoughts!