GP SoftwareTwitter
Opus FAQsManualCommandsObjects

ZIP compression level ignored

I added an item to all files and folders context menu so I can easily compress folders. The problem is DOpus sometimes ignores compression level set in preferences (for testing I set it to Store).

This command works good (testing folder is compressed in 30 seconds):

Copy Archive=zip Here CREATEFOLDER {sourcepath|nopath|noterm}

This command ignores compression level set to Store and takes much longer to compress (after 2 minutes it's like 2-3% complete).

Copy Archive=zip,single Here

(looks like "single" is the reason)

By the way, is there any way to specify compression level in a command itself? (Assuming I want use build-in archive support; but if you have any cool buttons for 7-zip, I'd be more than happy to see them.)

Oh, I'm using v12.3
Looks like adding "single" switch just makes the process much longer, regardless of compression level settings.

Using "single" currently switches Opus into using a non-batch mode, where the archive is opened and closed for each file that is added, making it a lot slower if there are a lot of files to add to each archive. (There's no reason you should have known this, it's just a quirk of how things are implemented on our side.)

Here's a script-button which does basically the same thing, and should work better. As a bonus, since it's a script it can be modified if you need more flexibility than "archive=single" provided.

As another bonus, the script also works with non-Zip formats, while I don't think "ARCHIVE=single" currently does.

The only really noteworthy thing about the script is that if a folder is selected and is empty, then it creates an empty archive rather than trying to create an archive from the folder (which would produce an unwanted "No work to do" error.)

(How to add buttons from this forum to your toolbars, Button .dcf Files section, for anyone who needs help with how to add the code below to a toolbar.)

Zip Single.dcf (2.5 KB)

Script code that is inside the .dcf file, just for reference:

function OnClick(clickData)
{
	var source = clickData.func.sourcetab;
	var cmd    = clickData.func.command;
	var work   = false;
	cmd.deselect = false; // Leave source files selected.
	cmd.ClearFiles();

	for (var e = new Enumerator(source.selected); !e.atEnd(); e.moveNext())
	{
		var f = e.item();

		if (IsEmptyDir(f))
		{
			var arcName = f.Path + "\\" + f.name_stem_m + ".zip";
			if (!DOpus.FSUtil.Exists(arcName))
			{
				work = true;
				cmd.AddLine("CreateFolder NAME=\"" + arcName + "\" ARCHIVE=.ZIP READAUTO=no NOUPDATESETTINGS");
			}
		}
		else
		{
			work = true;
			cmd.AddLine("Copy FILE=\"" + f.RealPath + "\" TO=\"" + f.Path + "\" ARCHIVE=.ZIP CREATEFOLDER=\"" + f.name_stem_m + ".zip\"");
		}
	}

	if (work)
	{
		cmd.Run();
	}
}

function IsEmptyDir(item)
{
	if (!item.is_dir)
	{
		return false;
	}

	var fe = DOpus.FSUtil.ReadDir(item.RealPath);

	return fe.complete;	
}

Ah, I see. Knowing this, I think there's simpler solution.

Copy {file} Archive=zip Here

Adding {file} makes DOpus execute the command for each selected item separately. Or maybe there are some disadvantages I don't know about and the script will work better? (Error message in case of empty folder is not a big deal.)

Thanks for the code anyway.

That might work equally well.

I tried something slightly different and started to run into problems, so I changed approach and went with a script. But I didn't try that exact command, so it may work fine.

For me, a script is more typing but often quicker/easier since it has explicit control over everything and there will be less surprises and more flexibility. But that's subjective and won't be the same for everyone.

your script code is fine Leo, This Script copy selected files and folders to zip file. Is there any way to Move Selected files and folders to the zip or rar file separately?

You could make the script run the Delete command on everything it compresses. I'm always a bit weary of that as you need to be careful about error handling. If creating the archive fails and the script doesn't catch it properly, deleting the source files might mean you lose the data. I suppose it's safe enough if the recycle bin is there and the files aren't too large for it.

On the other hand, the script should leave things selected after it completes, so you can just click the Delete button then if you're happy the archives were created correctly. I personally prefer deletion to be an explicit choice. (You would want Preferences / File Operations / Copy Options / Automatically select newly copied files to be turned off so the new archives aren't also selected.)

Thanks