Paste Here to New Subfolder

I found a script on the forums to modify, I have tried COPY MOVE, but I can't get it right. :disappointed_relieved:
I want to get the clipboard item name to create a folder, and then paste the clipboard item into this new folder without going into this folder.

function OnClick(clickData)
{
	var cmd = clickData.func.command;
	if (clickData.func.sourcetab.selected.count == 0)
	{
		cmd.RunCommand('CreateFolder READAUTO=no');
	}
	else
	{
		cmd.SetModifier('nofilenamequoting');
		cmd.AddLine('@set dir={dlgstrings|Paste Here To New Subfolder|{file|noext}}');
		cmd.AddLine('CREATEFOLDER "{$dir}"');
        cmd.AddLine('GO "{$dir}"');
        cmd.AddLine('Clipboard PASTE');
		cmd.Run();
	}
}

Try this:

function OnClick(clickData)
{
	var cmd = clickData.func.command;
	cmd.ClearFiles();

	if (DOpus.GetClipFormat() != 'files')
		return;

	var clipFiles = DOpus.GetClip('files');
	var firstName = clipFiles(0).name_stem_m;

	var fsu = DOpus.FSUtil;
	var path = clickData.func.sourcetab.path;
	path.Add(firstName);
	path = fsu.Resolve(path);

	cmd.RunCommand('CreateFolder READAUTO=no NAME="' + path + '"');
	cmd.SetSource(path);
	cmd.RunCommand('Clipboard PASTE');
}

Thanks a lot, but that script has a window to create a folder, and sometimes I need to modify the filename.

You can use dialog.GetString to prompt for a string from a script.

There's a good, short example here: Pin any executable to Start - #5 by Felix.Froemel

Thanks! how to make all text selected like Rename INLINE when creating a folder?

function OnClick(clickData)
{
	var cmd = clickData.func.command;
	cmd.ClearFiles();

	if (DOpus.GetClipFormat() != 'files')
		return;

	var clipFiles = DOpus.GetClip('files');
	var firstName = clipFiles(0).name_stem_m;

	var fsu = DOpus.FSUtil;
	var path = clickData.func.sourcetab.path;
	path = fsu.Resolve(path);

    var dialog = clickData.func.Dlg();
	var input = dialog.GetString("Select or enter folder name or subpath", firstName, 256, "OK|Cancel", "Paste (Copy) Here to New Subfolder", DOpus.Listers(0));
	if(dialog.result == "")
		DOpus.NewCommand.RunCommand(exit);
	cmd.RunCommand('CreateFolder READAUTO=no NAME="' + input + '"');
	path.Add(input);
	cmd.SetSource(path);
	cmd.RunCommand('Clipboard PASTE');
}

image
to
image

DOpus.Listers(0) may not be the lister you are running the script from. You can get the right lister via clickData, but you can also omit it entirely here, since the object clickData.func.Dlg gets you is already set up to use the correct lister as its parent window.

var input = dialog.GetString("Select or enter folder name or subpath", firstName, 256, "OK|Cancel", "Paste (Copy) Here to New Subfolder");

Also, change this:

	if(dialog.result == "")
		DOpus.NewCommand.RunCommand(exit);

To this:

	if(input == "")
		return;

We can do that using dialog.select = true, but that doesn't affect the simplified dialog.GetString helper, so we need to switch to doing things like this:

	var dialog = clickData.func.Dlg();
	dialog.title = "Paste (Copy) Here to New Subfolder";
	dialog.message = "Select or enter folder name or subpath";
	dialog.buttons = "OK|Cancel";
	dialog.max = 256;
	dialog.defvalue = firstName;
	dialog.select = true;
	dialog.Show();
	var input = dialog.input;
	if (dialog.result == 0 || input == "")
		return;

Putting it all together:

function OnClick(clickData)
{
	var cmd = clickData.func.command;
	cmd.ClearFiles();

	if (DOpus.GetClipFormat() != 'files')
		return;

	var clipFiles = DOpus.GetClip('files');
	var firstName = clipFiles(0).name_stem_m;

	var fsu = DOpus.FSUtil;
	var path = clickData.func.sourcetab.path;
	path = fsu.Resolve(path);

	var dialog = clickData.func.Dlg();
	dialog.title = "Paste (Copy) Here to New Subfolder";
	dialog.message = "Select or enter folder name or subpath";
	dialog.buttons = "OK|Cancel";
	dialog.max = 256;
	dialog.defvalue = firstName;
	dialog.select = true;
	dialog.Show();
	var input = dialog.input;
	if (dialog.result == 0 || input == "")
		return;

	cmd.RunCommand('CreateFolder READAUTO=no NAME="' + input + '"');
	path.Add(input);
	cmd.SetSource(path);
	cmd.RunCommand('Clipboard PASTE');
}
1 Like

I am a beginner, thanks for the detailed guide! :sparkling_heart:

1 Like

very useful