Zip each file from a flat view into a separate archive

A friend wanted to compress each file in a nested folder structure into a separate zip file that still resides in the same structure, e.g. turn something like this




where each zip file contains just the corresponding .txt file in its root with no other directories.

I think I succeeded in making a button to do this, refraining from using any external programs. Just turn on flat view mixed (no folders) in the source lister, select the files you want to turn into .zip, and press the button. For safety reasons this does NOT delete the original files. The deletion can be easily done manually, using flat view.

It took me a while to figure out how to access the path of files in flat view, so I will share the button here (the key was to use {filepath$|..}).

<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>Add To &amp;ZIP (each file separately)</label>
	<tip>Add each selected file to a separate ZIP file</tip>
	<function type="normal">
		<instruction>Copy {filepath$} ARCHIVE=single,keepfolder TO {filepath$|..} CREATEFOLDER={file$|noext}</instruction>