Here's the script to achieve what I told you in PM. It should do the trick.
PrintFolders.opusscriptinstall (1.9 KB)
Tell me if encounter issues.
It can also help you get a grasp of JScript code, which in the end is much more readable and easy to tweak than DOS command files
Code :
// PrintFolders
// (c) 2024 Stephane
// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/endpoints/redirect.php?page=scripts for development information.
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
initData.name = "PrintFolders";
initData.version = "1.0";
initData.copyright = "(c) 2024 Stephane";
// initData.url = "https://resource.dopus.com/c/buttons-scripts/16";
initData.desc = "";
initData.default_enable = true;
initData.min_version = "12.0";
}
// Called to add commands to Opus
function OnAddCommands(addCmdData)
{
var cmd = addCmdData.AddCommand();
cmd.name = "PrintMyFolders";
cmd.method = "OnPrintMyFolders";
cmd.desc = "";
cmd.label = "PrintMyFolders";
cmd.template = "DEST1/K,FORMAT1/K,DEST2/K,FORMAT2/K,DEST3/K,FORMAT3/K,DONE_FILE/K,VERBOSE_FOLDERS/S";
cmd.hide = false;
cmd.icon = "script";
}
// Implement the PrintMyFolders command
function OnPrintMyFolders(scriptCmdData)
{
// Init required data
// ===================
var foldersList1 = new Array();
foldersList1.push("/profile/Videos");
foldersList1.push("/profile/Pictures");
foldersList1.push("B:\\Local Downloads\\tmp\\tmp\\for quotes");
// ... to be completed
var foldersList2 = new Array();
foldersList2.push("/programfiles");
foldersList2.push("/programfilesx86");
var foldersList3 = new Array();
foldersList3.push("/profile/OneDrive");
// To be completed
// Get command args
var cdf = scriptCmdData.func;
var dest1 = "", dest2 = "", dest3 = "";
var fmt1 = "", fmt2 = "", fmt3 = "";
var verboseFolders = false;
var doneFile = "";
if (!cdf.args.got_arg.dest1) {
dout("Error : No destination 1 provided. Exiting.");
return;
}
else dest1 = cdf.args.dest1;
if (!cdf.args.got_arg.dest2) {
dout("Error : No destination 2 provided. Exiting.");
return;
}
else dest2 = cdf.args.dest2;
if (!cdf.args.got_arg.dest3) {
dout("Error : No destination 3 provided. Exiting.");
return;
}
else dest3 = cdf.args.dest3;
if (!cdf.args.got_arg.format1) {
dout("Error : No format 1 provided. Exiting.");
return;
}
else fmt1 = cdf.args.format1;
if (!cdf.args.got_arg.format2) {
dout("Error : No format 2 provided. Exiting.");
return;
}
else fmt2 = cdf.args.format2;
if (!cdf.args.got_arg.format3) {
dout("Error : No format 3 provided. Exiting.");
return;
}
else fmt3 = cdf.args.format3;
if (!cdf.args.got_arg.done_file) {
dout("Error : No done file provided. Exiting.");
return;
}
else doneFile = cdf.args.done_file;
if (cdf.args.got_arg.verbose_folders)
verboseFolders = true;
// end of command args
var fsu = DOpus.FSUtil;
var cmd = DOpus.Create.Command();
// Cleaning done file & dest files
cmd.AddFile(fsu.Resolve(doneFile));
cmd.AddFile(fsu.Resolve(dest1));
cmd.AddFile(fsu.Resolve(dest2));
cmd.AddFile(fsu.Resolve(dest3));
cmd.RunCommand("DELETE FORCE NORECYCLE QUIET");
cmd.ClearFiles();
dout("Processing List 1");
ProcessFolders(foldersList1, "grouped", fmt1, dest1, verboseFolders);
dout("Processing List 2");
ProcessFolders(foldersList2, "no", fmt2, dest2, verboseFolders);
dout("Processing List 3");
ProcessFolders(foldersList3, "grouped", fmt3, dest3, verboseFolders);
// Job done, writing job done
var jobDone = fsu.OpenFile(doneFile, "wa");
jobDone.Close();
}
function ProcessFolders(foldersList, flat, fmt, dest, verboseFolders) {
var fsu = DOpus.FSUtil;
var cmd = DOpus.Create.Command();
var destFile = fsu.OpenFile(dest, "rw");
var tmp = fsu.GetTempDirPath() + "\\tmp_out.txt";
for (var i=0; i < foldersList.length; i++) {
var folder = fsu.Resolve(foldersList[i]);
dout('[1] Folder #' + i + ' : "' + folder + '"');
var action = 'Print FOLDER "' + folder + '" TO "' + tmp + '" ';
action += 'AS=tab ENCODING=UTF8 FLATVIEW=' + flat + ' ';
action += 'FORMAT="' + fmt + '" QUIET';
dout("Action ==> >" + action + "<");
cmd.RunCommand(action);
var contentFile = fsu.OpenFile(tmp, "r");
dout("File = " + contentFile.path + " | size = " + contentFile.size);
var content = contentFile.Read();
contentFile.Close();
destFile.Write("\n");
if (verboseFolders) destFile.Write("*** " + folder + " ***\n");
destFile.Write(content);
}
destFile.Close();
cmd.AddFile(tmp);
cmd.RunCommand("DELETE FORCE NORECYCLE QUIET");
}
///////////////////////////////////////////////////////////////////////////
// Helper dout function
function dout(msg, error, time) {
if (error == undefined) error = false;
if (time == undefined) time = true;
DOpus.output(msg, error, time);
}
What you need to modify in the script
Starting line 43 (foldersList1.push("/profile/Videos");
), add the folders you want in the first extract (grouped FLATVIEW).
Lines 49 and 50 should already be ok with what you're doing.
Line 53 (foldersList3.push("/profile/OneDrive");
) you can add another line for another folder (probably /profile/Dropbox
).
When specifying those folders, you can :
- Use aliases as I did for most of them (
/profile
, /programfiles
, ...). All of these should be Opus standards. Of course, you can use your own.
- Use full standard path.
- Mix and match (starting with the alias).
Just be careful when using \
: they all need to be escaped by another \
like on line 45 :
foldersList1.push("B:\\Local Downloads\\tmp\\tmp\\for quotes");
And that will be all for the script.
How the command added by the script works
The script adds a new command to Opus (PrintMyFolders
) that you will then be able to call from dopusrt.
That command takes the following parameters :
Parameter |
Mandatory ? |
Comment |
DEST1 |
YES |
Gives the full destination path of the file for the first batch of folders (which uses FLATVIEW=grouped) |
FORMAT1 |
YES |
Specifies the folder format to be used by the Print command called from within the script for the first batch of folders |
DEST2 |
YES |
Same as DEST1 but for the second list of folders (which uses FLATVIEW=no) |
FORMAT2 |
YES |
Same as FORMAT1 but for the second list of folders |
DEST3 |
YES |
Same as DEST1 but for the third list of folders (which uses FLATVIEW=grouped) |
FORMAT3 |
YES |
Same as FORMAT1 but for the third list of folders |
DONE_FILE |
YES |
Full path of the file that will be written once everything is done. That's the one you will have to monitor the appearance to know job's done ! |
VERBOSE_FOLDERS |
NO |
Acts as a switch. When specified, before the result of each Print command, a line will be insterted in the output in the likes of '*** ***' |
Even if DONE_FILE is erased at the begining of the command, I strongly advise that you also delete it in your script before calling dopusrt and then waiting for it to appear.
So, in the end, your command line should look something like this :
"C:\Program Files\Directory Opus\dopusrt.exe" /cmd DEST1 "%Filförteckn%.1.txt" FORMAT1 "För skapande av filförteckning" DEST2 "%Filförteckn%.2.txt" FORMAT2 "För skapande av filförteckning" DEST3 "%Filförteckn%.3.txt" FORMAT3 "För skapande av filförteckning" DONE_FILE "%Filförteckn%.done"
Up to you to use the VERBOSE_FOLDERS at the end or not (if you want to keep current format, do not use it).
As discussed, once you have launched this with dopusrt, do the other DIR /S
outputs to some other file and once the DONE_FILE appears, concatenate the files in the proper order (type fileA fileB fileC fileD > finalFile
).
One last thing : I don't think I've used something specific to Opus13, but if you get errors (for that or something else), let me know.