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:
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();
}
}
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.
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
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.
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.)
// 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
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.