Quick buttons for directory organisation

Copying selected objects to a certain pre-defined destination

Would somebody please help me with the following button or hotkey:

I frequently need to move files/folders that I previously manually selected from a network folder to a folder on C:.
I would like it to work exactly as if I used simple cut / paste, i.e. with progress window and with requests in case of identicaly files in destination.

(The context is that I am copying downloaded files from the MAC download folder (which appears as a network drive in the Windows VM) to the Downloads folder in the Windows VM because I want downloads of Mac and Windows to accumulate in one place (i.e., everything in the VM), but don't want to download from Mac INTO the VM directly because the VM is sometimes not running.)

There is also this thread, I wasn't sure where best to post:

The copy command has a to argument for specifying a fixed destination path.

If you need more help, please start a thread in Help & Support.

Leo, I am answering here still because I think it makes more sense. I hope this is OK -- see below:

I now use a button that does

Copy TO "C:\Users\matthiasernst\Downloads" MOVE

and it works exactly as I want. I hope it's the correct solution.

I am now quoting the above message of user "aussieboykie" because I think there is some problems there which confused me.
First of all, as mentioned by Jon, RENAMEWHENSAME is a bit confusing because it does NOT refer to supression of the rename dialogue (making it automatic). It's idea is to address the situation where you copy a file to the same folder with the intention of creating a copy within the same folder, where a prompt makes no sense. However, MOVING a file within the same folder makes no sense -- indeed, you get an error message. Thus I believe (?) RENAMEWHENSAME only makes sense in combination with COPY that does NOT have a MOVE action specified -- and thus user aussieboykie might not have understood the command?

WHENEXISTS=rename may be what you want instead of RENAMEWHENSAME.

Not sure which message/comment by Jon you're referring to, though. He hasn't posted in this thread or the other one you linked to.

This thread is very difficult to follow with so many unrelated questions under it, which is why a new thread would be better. (You can always put a link to it here if you think it would be useful for other people.)

Very useful functions (for me) that I think Dopus should have built in...
Move Here to New Subfolder:

function OnClick(clickData)
{
	var cmd = clickData.func.command;
	var tab = clickData.func.sourcetab;
	if (clickData.func.sourcetab.selected.count == 0)
	{
		cmd.RunCommand('CreateFolder READAUTO=no');
	}
	else
	{
	
	var focusI = tab.GetFocusItem.name_stem;                                          //Get the base name of the item in focus
    for(var e = new Enumerator(clickData.func.sourcetab.selected); !e.atEnd(); e.moveNext()) {   //Each item
	if(focusI == e.item().name_stem) {var icase = 1; break;}                          //If the focused item is in the selected items, set icase to 1 and exit the loop
    }
	 
	if(icase != 1) {var focusI = tab.selected(0).name_stem;}                          //If the focused item is not in the selected items, set focusI equal to the base name of the first item in the selected items
	cmd.AddLine('@set dir={dlgstrings|Enter new subfolder name|"' + focusI + '"}');   //Use the base name of the item to create the folder
	cmd.AddLine('Copy MOVE HERE CREATEFOLDER="{$dir}"');                              //Create a folder and move the selected items into it
	cmd.Run();
 }
}

Paste Here to New Subfolder

What confuses me even more is that searched the help documents and forums can't find this type of input and drop down window script parameter:
DLG

is there any way to get the first one to work in 2 pane mode? bc when you have something selected in pane 1 and hit the button in pane 2, it just makes an empty folder.

1 Like

If you want to select files on one side and more them into a new sub-folder on the other side:

Copy MOVE CREATEFOLDER

Run the button from the side with the selected files, not the side you want them to go into.

Sweet that worked perfectly, thank you!

Move Here to New Subfolder.
image
new
image
Move Here to New Subfolder (JS) v1.6.1.txt (4.1 KB)
dlg.Control("static3").label = "D:\\Icons\\MOVE.png"; // Icon

Move Here to New Subfolder ====================================================
User-defined command:movehere-sf
Move Here to New Subfolder v1.6.1.osp (17.2 KB)
Button: Move Here to New Subfolder.dcf (278 Bytes)
dlg.Control("static3").label = Script.LoadImage("Move.png"); // Icon

Move Here to New Subfolder (Folder name history drop-down list) ========================
User-defined command:movehere-sf-h
image
Move Here to New Subfolder v1.6.1 (Folder name history drop-down list).osp (20.1 KB)
image
Move Here to New Subfolder v1.6.1 (Path & Folder name history drop-down list).osp (20.7 KB)

You don't need a script to do that. You can do it in one line:

Copy MOVE HERE CREATEFOLDER
  • Item name drop-down list. . .

First post, so hello everyone,

After encountering issues with the "Move Everything Up" button, I've made some improvements and wanted to share it with the community. The main problem was that it moved all files and folders simultaneously. This caused a conflict when there were files and subfolders with the same name.

With original button script One/One/note.txt conflicts, at least for me, with One/note.txt

desktop/
└── One/
    ├── // button executed from here
    ├── note.txt
    └── One/
        └── note.txt

I've modified the script to move all files in the current directory up one level before proceeding with the folders. It should help avoid conflicts when there are files and subfolders with the same name.

Here's the improved button script written in JScript:

// Initiate the click event function
function OnClick(clickData) {
    var cmd = clickData.func.command;
    cmd.deselect = false; // Prevent automatic deselection

    // Define the current path and parent path
    var currentPath = clickData.func.sourcetab.path;
    var parentPath = String(currentPath).split("\\");
    parentPath.pop();
    parentPath = parentPath.join("\\");

    // Initiate a dialog box for user confirmation
    var dlg = clickData.func.Dlg; // Initiate a dialog
    dlg.message = "Move all the files and folders in the current directory up one level and then delete the current folder?";
    dlg.title = "Move Everything Up";
    dlg.buttons = "No|Yes";
    dlg.icon = "question";
    var result = dlg.Show();

    // If user confirms, proceed with the operation
    if (result == 0) {
        try {
            // Move files first
            var fileEnum = new Enumerator(clickData.func.sourcetab.files);
            while (!fileEnum.atEnd()) {
                var item = fileEnum.item();
                if (!item.is_dir) {
                    // Make sure the file exists before moving
                    if (DOpus.FSUtil.Exists(item)) {
                        cmd.RunCommand('Copy MOVE FILE="' + item + '" TO="' + parentPath + '"');
                    }
                }
                fileEnum.moveNext();
            }

            // Then move directories
            var dirEnum = new Enumerator(clickData.func.sourcetab.dirs);
            while (!dirEnum.atEnd()) {
                var item = dirEnum.item();
                // Make sure the directory exists before moving
                if (DOpus.FSUtil.Exists(item)) {
                    cmd.RunCommand('Copy MOVE FILE="' + item + '" TO="' + parentPath + '"');
                }
                dirEnum.moveNext();
            }

            // Go to the parent directory
            cmd.RunCommand('Go PATH="' + parentPath + '"');

            // If the original directory is empty, delete it
            if (DOpus.FSUtil.Exists(currentPath)) {
                cmd.RunCommand('Delete FILE="' + currentPath + '" NORECYCLE SKIPNOTEMPTY QUIET');
            }
        } catch(e) {
            // Log any error to the output
            DOpus.Output("An error occurred: " + e.message);
        }
    }
}

If anyone has insights on how to resolve this issue using just DOpus scripting, please share your suggestions.

Move Everything Up.dcf (4.4 KB)

1 Like

Original button works OK for me in that scenario. At least, there aren't any errors and the files seem to end up in the right place, from a quick check.

(There was an issue with the button missing quotes on the line that removes the old folder, which I've fixed in the root post.)

I messed up my example. Not every file/folder name is treated the same.

Working / not working scenarios:

Comparison with my script:

Hard to see and recreate from a video. A text tree like in your previous post would be easier to follow.

How does a change in the processing order solve name conflicts?

Here you go, examples from video:

// Doesn't work
Test/
└── One/
    ├── // button executed from here
    ├── One.txt
    └── One/
        └── One.txt

// Doesn't work
Test/
└── One/
    ├── // button executed from here
    ├── Two.txt
    └── One/
        └── Two.txt

// Worked
Test/
└── Two/
    ├── // button executed from here
    ├── One.txt
    └── Two/
        └── One.txt

@lxp Best explained with example, assume you first move subdirectories:

Test/
└── One/
    ├── One.txt
    └── One/ //  "This goes down one level and merges with Test/One/
        └── One.txt // "So this also goes one level down, and we have conflict to resolve

Which Opus version do you use?

I use Opus Pro v12.33 x64 (build 8659, 2023/09/16) to be exact.

Thanks, much clearer!

In Opus 13, you could solve it like this, moving the files directly below the starting point before moving anything else:

@set ChildPath={sourcepath$|noterm}
Copy MOVE * TO .. FILTERDEF type match files and subfolder nomatch (name match *)
Copy MOVE * TO .. FILTERDEF name match *
Go ..
Delete FILE="{$ChildPath}" NORECYCLE SKIPNOTEMPTY QUIET

In Opus 12, commands can't define filters on the fly like this, but could use the same approach by creating the two filters under Preferences / File Operations / Filters and referring to them by their names and the FILTER argument.

1 Like