This script creates in the source a zip-archive that contains a lightweight mirror of the selected files and folders. All files in the archive are empty and have a size of zero. It is helpful if you quickly want to share test cases or want to get support for e.g. file renaming. Note that the files contain no metadata other than what is stored in the file system.
Sound familiar? Yep, it's this script's little brother.
Update 2022-07-05: Made it easier to pick a target folder other than the source for the zip file.
// https://resource.dopus.com/t/robocopy-folder-mirror-archive/39032
// 2022-07-05
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
var dtab = clickData.func.desttab;
var dlg = clickData.func.Dlg();
var fsu = DOpus.FSUtil();
var wsh = new ActiveXObject('WScript.Shell');
cmd.deselect = false;
if (tab.selected.count == 0) return;
var srcPath = String(tab.path).replace(/\\$/, ''); // to make Robocopy work with files in root
var tmpPath = fsu.GetTempDirPath();
var zipStem = 'RFM-' + DOpus.Create().Date().Format('D#yyyyMMdd-T#HHmmss');
// zip goes to (pick one)...
// ... source
var zipPath = srcPath;
// ... destination
// var zipPath = dtab.path;
// ... Desktop
// var zipPath = fsu.Resolve('/desktop');
// ... user's choice
// var zipPath = dlg.Folder('Pick target folder for zip file', '/profile', true);
// if (!zipPath.result) return; // user has cancelled
DOpus.ClearOutput();
for (var e = new Enumerator(tab.selected_dirs); !e.atEnd(); e.moveNext()) {
var item = e.item();
var cmdLine = 'Robocopy.exe "' + item + '" "' + tmpPath + '\\' + item.name + '" /E /CREATE';
DOpus.Output(cmdLine);
wsh.Run(cmdLine, 0, true);
}
if (tab.selected_files.count > 0) {
var cmdLine = 'Robocopy.exe "' + srcPath + '" "' + tmpPath + '"';
for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
var item = e.item();
cmdLine += ' "' + item.name + '"';
}
cmdLine += ' /CREATE';
DOpus.Output(cmdLine);
wsh.Run(cmdLine, 0, true);
}
cmd.RunCommand('Copy ARCHIVE=keepfolder FILE="' + tmpPath + '\\*" TO="' + zipPath + '" CREATEFOLDER="' + zipStem + '"');
cmd.RunCommand('GO PATH="' + zipPath + '\\' + zipStem + '.zip" OPENCONTAINER NEWTAB OPENINDUAL');
cmd.RunCommand('GO PATH="' + tmpPath + '" NEWTAB=nofocus OPENINDUAL');
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Robocopy Folder Mirror Archive</label>
<icon1>#copy</icon1>
<function type="script">
<instruction>@script JScript</instruction>
<instruction>// https://resource.dopus.com/t/robocopy-folder-mirror-archive/39032</instruction>
<instruction />
<instruction>// 2022-07-05</instruction>
<instruction />
<instruction>function OnClick(clickData) {</instruction>
<instruction> var cmd = clickData.func.command;</instruction>
<instruction> var tab = clickData.func.sourcetab;</instruction>
<instruction> var dtab = clickData.func.desttab;</instruction>
<instruction> var dlg = clickData.func.Dlg();</instruction>
<instruction> var fsu = DOpus.FSUtil();</instruction>
<instruction> var wsh = new ActiveXObject('WScript.Shell');</instruction>
<instruction> cmd.deselect = false;</instruction>
<instruction />
<instruction> if (tab.selected.count == 0) return;</instruction>
<instruction />
<instruction> var srcPath = String(tab.path).replace(/\\$/, ''); // to make Robocopy work with files in root</instruction>
<instruction> var tmpPath = fsu.GetTempDirPath();</instruction>
<instruction> var zipStem = 'RFM-' + DOpus.Create().Date().Format('D#yyyyMMdd-T#HHmmss');</instruction>
<instruction />
<instruction> // zip goes to (pick one)...</instruction>
<instruction />
<instruction> // ... source</instruction>
<instruction> var zipPath = srcPath;</instruction>
<instruction />
<instruction> // ... destination </instruction>
<instruction> // var zipPath = dtab.path;</instruction>
<instruction />
<instruction> // ... Desktop </instruction>
<instruction> // var zipPath = fsu.Resolve('/desktop');</instruction>
<instruction />
<instruction> // ... user's choice</instruction>
<instruction> // var zipPath = dlg.Folder('Pick target folder for zip file', '/profile', true); </instruction>
<instruction> // if (!zipPath.result) return; // user has cancelled</instruction>
<instruction />
<instruction> DOpus.ClearOutput();</instruction>
<instruction />
<instruction> for (var e = new Enumerator(tab.selected_dirs); !e.atEnd(); e.moveNext()) {</instruction>
<instruction> var item = e.item();</instruction>
<instruction> var cmdLine = 'Robocopy.exe "' + item + '" "' + tmpPath + '\\' + item.name + '" /E /CREATE';</instruction>
<instruction> DOpus.Output(cmdLine);</instruction>
<instruction> wsh.Run(cmdLine, 0, true);</instruction>
<instruction> }</instruction>
<instruction />
<instruction> if (tab.selected_files.count > 0) {</instruction>
<instruction> var cmdLine = 'Robocopy.exe "' + srcPath + '" "' + tmpPath + '"';</instruction>
<instruction> for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {</instruction>
<instruction> var item = e.item();</instruction>
<instruction> cmdLine += ' "' + item.name + '"';</instruction>
<instruction> }</instruction>
<instruction> cmdLine += ' /CREATE';</instruction>
<instruction> DOpus.Output(cmdLine);</instruction>
<instruction> wsh.Run(cmdLine, 0, true);</instruction>
<instruction> }</instruction>
<instruction />
<instruction> cmd.RunCommand('Copy ARCHIVE=keepfolder FILE="' + tmpPath + '\\*" TO="' + zipPath + '" CREATEFOLDER="' + zipStem + '"');</instruction>
<instruction />
<instruction> cmd.RunCommand('GO PATH="' + zipPath + '\\' + zipStem + '.zip" OPENCONTAINER NEWTAB OPENINDUAL');</instruction>
<instruction> cmd.RunCommand('GO PATH="' + tmpPath + '" NEWTAB=nofocus OPENINDUAL');</instruction>
<instruction>}</instruction>
</function>
</button>
https://resource.dopus.com/t/how-to-use-buttons-and-scripts-from-this-forum/3546