This script creates a lightweight directory mirror of the active drive. The mirror sits in the default location /dropbox\Mirror
and consists of the drive label as top folder and all files and folders below it. All files are empty and have a size of zero. The mirror also contains some info files regarding the drive's space.
A mirror like this is most useful as a catalog for external drives, but also works well as a test case for copy and rename buttons (as long as they don't use metadata which is absent).
The script uses the Windows system tool Robocopy.exe
. The core functionality is in just one line, the rest is simply putting together the parameters. If you are into scripting, you might find the parts that collect the drive info interesting.
In my experience, Dropbox works really well even with big mirrors. Any future run of the script will only add/change/remove the files that are affected, thus keeping the number of files to be synced small.
2021-07-29: Use this script, if you only want to mirror a few files and folders.
// https://resource.dopus.com/t/robocopy-drive-mirror/34872
// Version 2021-07-29
// - Destination path gets space info as comment
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
var dlg = clickData.func.Dlg();
var fsu = DOpus.FSUtil();
var fso = new ActiveXObject('Scripting.FileSystemObject');
var wsh = new ActiveXObject('WScript.Shell');
cmd.deselect = false;
var mirrorPath = fsu.Resolve('/dropbox\\Mirror'); // Change here as needed; use double backslashes
tab.path.Root();
var srcPath = tab.path;
if (srcPath.drive == 0) {
dlg.Request('Please select a drive!', 'OK');
return;
}
if (srcPath.drive == mirrorPath.drive) {
dlg.Request('Please do not select the mirror drive!', 'OK');
return;
}
var srcDrive = fso.GetDrive(srcPath);
var srcLabel = srcDrive.VolumeName;
var oneGB = 1024 * 1024 * 1024;
var srcFree = Math.round(srcDrive.FreeSpace / oneGB);
var srcTotal = Math.round(srcDrive.TotalSize / oneGB);
var dstPath = mirrorPath + '\\' + srcLabel;
cmd.RunCommand('CreateFolder NAME="' + dstPath + '"');
cmd.RunCommand('SetAttr FILE="' + dstPath + '" META "usercomment:' + srcFree + ' GB free / ' + srcTotal + ' GB total"');
cmd.RunCommand('Go PATH="' + srcPath + '" DUALPATH="' + dstPath + '"');
if (tab.right) cmd.RunCommand('Go SWAP');
cmd.RunCommand('Delete FILE="' + dstPath + '\\*.txt" QUIET');
wsh.Run('Robocopy.exe ' + srcPath + ' "' + dstPath + '" /S /CREATE /PURGE /NOCOPY', 0, true); // no quotes around srcPath because it ends with backslash
cmd.RunCommand('Print FOLDER="' + srcPath + '" TO="' + dstPath + '\\dirlist.txt" AS=txt FLATVIEW=no CALCSIZES=yes QUIET');
cmd.RunCommand('FileType NEW=.txt PATH="' + dstPath + '" NEWNAME="norename:' + srcFree + ' GB free.txt"');
cmd.RunCommand('FileType NEW=.txt PATH="' + dstPath + '" NEWNAME="norename:' + srcTotal + ' GB total.txt"');
cmd.RunCommand('FileType NEW=.txt PATH="' + dstPath + '" NEWNAME="norename:' + (srcTotal - srcFree) + ' GB used.txt"');
cmd.RunCommand('Delete FILE="' + dstPath + '\\$RECYCLE.BIN" QUIET');
cmd.RunCommand('Delete FILE="' + dstPath + '\\System Volume Information" QUIET');
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
<label>Robocopy Drive Mirror</label>
<icon1>#copy</icon1>
<function type="script">
<instruction>@script JScript</instruction>
<instruction />
<instruction>// Version 2021-07-29</instruction>
<instruction>// - Destination path gets space info as comment</instruction>
<instruction />
<instruction>function OnClick(clickData) {</instruction>
<instruction> var cmd = clickData.func.command;</instruction>
<instruction> var tab = clickData.func.sourcetab;</instruction>
<instruction> var dlg = clickData.func.Dlg();</instruction>
<instruction> var fsu = DOpus.FSUtil();</instruction>
<instruction> var fso = new ActiveXObject('Scripting.FileSystemObject');</instruction>
<instruction> var wsh = new ActiveXObject('WScript.Shell');</instruction>
<instruction> cmd.deselect = false;</instruction>
<instruction />
<instruction> var mirrorPath = fsu.Resolve('/dropbox\\Mirror'); // Change here as needed; use double backslashes</instruction>
<instruction />
<instruction> tab.path.Root();</instruction>
<instruction> var srcPath = tab.path;</instruction>
<instruction />
<instruction> if (srcPath.drive == 0) {</instruction>
<instruction> dlg.Request('Please select a drive!', 'OK');</instruction>
<instruction> return;</instruction>
<instruction> }</instruction>
<instruction />
<instruction> if (srcPath.drive == mirrorPath.drive) {</instruction>
<instruction> dlg.Request('Please do not select the mirror drive!', 'OK');</instruction>
<instruction> return;</instruction>
<instruction> }</instruction>
<instruction />
<instruction> var srcDrive = fso.GetDrive(srcPath);</instruction>
<instruction> var srcLabel = srcDrive.VolumeName;</instruction>
<instruction> var oneGB = 1024 * 1024 * 1024;</instruction>
<instruction> var srcFree = Math.round(srcDrive.FreeSpace / oneGB);</instruction>
<instruction> var srcTotal = Math.round(srcDrive.TotalSize / oneGB);</instruction>
<instruction> var dstPath = mirrorPath + '\\' + srcLabel;</instruction>
<instruction />
<instruction> cmd.RunCommand('CreateFolder NAME="' + dstPath + '"');</instruction>
<instruction> cmd.RunCommand('SetAttr FILE="' + dstPath + '" META "usercomment:' + srcFree + ' GB free / ' + srcTotal + ' GB total"');</instruction>
<instruction />
<instruction> cmd.RunCommand('Go PATH="' + srcPath + '" DUALPATH="' + dstPath + '"');</instruction>
<instruction> if (tab.right) cmd.RunCommand('Go SWAP');</instruction>
<instruction />
<instruction> cmd.RunCommand('Delete FILE="' + dstPath + '\\*.txt" QUIET');</instruction>
<instruction />
<instruction> wsh.Run('Robocopy.exe ' + srcPath + ' "' + dstPath + '" /S /CREATE /PURGE /NOCOPY', 0, true); // no quotes around srcPath because it ends with backslash</instruction>
<instruction />
<instruction> cmd.RunCommand('Print FOLDER="' + srcPath + '" TO="' + dstPath + '\\dirlist.txt" AS=txt FLATVIEW=no CALCSIZES=yes QUIET');</instruction>
<instruction> cmd.RunCommand('FileType NEW=.txt PATH="' + dstPath + '" NEWNAME="norename:' + srcFree + ' GB free.txt"');</instruction>
<instruction> cmd.RunCommand('FileType NEW=.txt PATH="' + dstPath + '" NEWNAME="norename:' + srcTotal + ' GB total.txt"');</instruction>
<instruction> cmd.RunCommand('FileType NEW=.txt PATH="' + dstPath + '" NEWNAME="norename:' + (srcTotal - srcFree) + ' GB used.txt"');</instruction>
<instruction />
<instruction> cmd.RunCommand('Delete FILE="' + dstPath + '\\$RECYCLE.BIN" QUIET');</instruction>
<instruction> cmd.RunCommand('Delete FILE="' + dstPath + '\\System Volume Information" QUIET');</instruction>
<instruction>}</instruction>
</function>
</button>
https://resource.dopus.com/t/how-to-use-buttons-and-scripts-from-this-forum/3546