Quick buttons for directory organisation

Just a few quick buttons that I've made that I find insanely useful if you need to move files around, particularly if you're moving them up / down the folder hierarchy.


Button commands are provided for easy reading. XML versions are also included for easier adding to toolbars. See How to use buttons and scripts from this forum.


1) Move selected items into a new sub-folder:

The first button creates a new folder - nothing new there - but if you've got any files selected when you do it it'll move them into your new folder. Simple but effective.

Opus 12 and later (may also work with Opus 11):

  • Set Function drop-down to Script Function
  • Set Script Type drop-down to JScript
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|Enter new subfolder name|{file|noext}}');
		cmd.AddLine('Copy MOVE HERE CREATEFOLDER="{$dir}"');
		cmd.Run();
	}
}
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>Move into new folder</label>
	<icon1>#makedir</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>function OnClick(clickData)</instruction>
		<instruction>{</instruction>
		<instruction>	var cmd = clickData.func.command;</instruction>
		<instruction>	if (clickData.func.sourcetab.selected.count == 0)</instruction>
		<instruction>	{</instruction>
		<instruction>		cmd.RunCommand(&apos;CreateFolder READAUTO=no&apos;);</instruction>
		<instruction>	}</instruction>
		<instruction>	else</instruction>
		<instruction>	{</instruction>
		<instruction>		cmd.SetModifier(&apos;nofilenamequoting&apos;);</instruction>
		<instruction>		cmd.AddLine(&apos;@set dir={dlgstrings|Enter new subfolder name|{file|noext}}&apos;);</instruction>
		<instruction>		cmd.AddLine(&apos;Copy MOVE HERE CREATEFOLDER=&quot;{$dir}&quot;&apos;);</instruction>
		<instruction>		cmd.Run();</instruction>
		<instruction>	}</instruction>
		<instruction>}</instruction>
	</function>
</button>

Opus 11 and earlier:

@nofilenamequoting
@set dir = {dlgstring|Enter new subfolder name|{file|noext}}
createfolder NAME="{$dir}" READAUTO=no
Copy MOVE TO=".\{$dir}"
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>Move into new folder</label>
	<icon1>#makedir</icon1>
	<function type="normal">
		<instruction>@nofilenamequoting</instruction>
		<instruction>@set dir = {dlgstring|Enter new subfolder name|}</instruction>
		<instruction>createfolder NAME=&quot;{$dir}&quot; READAUTO=no</instruction>
		<instruction>Copy MOVE TO=&quot;.\{$dir}&quot;</instruction>
	</function>
</button>

2) Move everything up:

The second button takes all the files and folders in the current directory, moves them up one level, and then deletes the current folder. So essentially c:\one\two\fileA.txt becomes c:\one\fileA and the folder 'two' is deleted. These two buttons are kinda opposites of each other.

Opus 12 and later:

@set ChildPath={sourcepath$|noterm}
Copy MOVE * TO ..
Go ..
Delete FILE="{$ChildPath}" NORECYCLE SKIPNOTEMPTY QUIET
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>Delete Folder and move contents up</label>
	<icon1>#opentoolbar</icon1>
	<function type="normal">
		<instruction>@set ChildPath={sourcepath$|noterm}</instruction>
		<instruction>Copy MOVE * TO ..</instruction>
		<instruction>Go ..</instruction>
		<instruction>Delete FILE=&quot;{$ChildPath}&quot; NORECYCLE SKIPNOTEMPTY QUIET</instruction>
	</function>
</button>

Opus 11 and earlier:

<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
   <label>Delete Folder and move contents up</label>
   <icon1>#opentoolbar</icon1>
   <function type="batch">
      <instruction>@set ChildPath={sourcepath$|noterm}</instruction>
      <instruction>@runmode hide</instruction>
      <instruction>Copy MOVE * TO ..</instruction>
      <instruction>Go ..</instruction>
      <instruction>rmdir {$ChildPath}</instruction>
   </function>
</button>

(Opus 11 version uses the DOS "rmdir" command to remove the directory, to avoid removing it if it is non-empty. This is important if what you are moving up contains another directory with the same name as the directory you started in. The Opus 12 version uses SKIPNOTEMPTY to do the same thing with the built-in delete command.)

6 Likes

Hi, everyone!

If you are slow-brain-fast-mouse user like me (no offence, please) you can use this modifier as the first line in the second (move-delete) command:

@confirm Move all the files and folders in the current directory up one level and then delete the current folder?

which will give you chance to cancel it.

4 Likes

Copying out of Flat View (Mixed, No Folders) mode into somewhere else is one way to do it. You'd need to delete the folders as a separate step.

You might find this small tool I wrote a while ago useful, although I don't think it will delete the folders either and it renames the files (to avoid name clashes and keep files from the same folder together):

DirFlatten

In case it's useful, here is a simplified button to move selected items into a new sub-folder. This isn't quite the same as the button in the first post as this button won't do anything if nothing is selected. (The button in the first post always creates the new folder whether or not there are selected items to move into it.)

Copy MOVE HERE CREATEFOLDER

To do the same, but automatically name the folder after the selected file (without extension):

@nofilenamequoting
Copy MOVE HERE CREATEFOLDER="{file|noext}"
3 Likes

I often use this code to move selected files to the parent folder. Works a treat.

Copy TO ..\ MOVE RENAMEWHENSAME FILTER=shift

RENAMEWHENSAME adds an element of safety.
FILTER=shift gives you a mechanism for specifying a filter "on the fly" using the shift key.

Regards, AB

You should be in the "two" folder when you run the button. It will move everything ("fileA.txt") from the current folder ("two") up a level (to the "one" folder).

If you are in the "one" folder when you run the button, then it will move "two" up a level, to C:\.

Fixed

createfolder ".\{$dir}" READAUTO=no

Will allow it to work with folders and files.

/Fixed

The code to move items into a subfolder works when files are selected, but when only folders are selected, it gives an error saying can't find the path.

What seems to happen is the folder I type in the dialog never gets created. Is there a modifier/argument change that would allow this to work for any combination of files/folders?

Thanks

1 Like

I've updated the root post's 2nd example with an improved version for Opus 12 which no longer needs to use the DOS rmdir command.

3 Likes
Copy MOVE TO ..
Go UP
Delete

It's a long time that I'm using this, what is the difference?

That won't check that the folder it is deleting is empty. If it has a sub-folder with the same name as itself (not that uncommon) and you move everything up a level, you'll then delete a non-empty folder.

Ah, ok. Since mine needs to select before and for deletion asks for confirmation, I have no problem with it.

This is I think the closest thread ive found but still not quite there, I need to flatten several folders and create a button to batch move the txt files up to the parent folder. Then delete the sub-folders. Essentially...

Parent Folder/sub1/sub2/filename.txt
to
Parent Folder/filename.txt

I keep finding threads that require me to click into the sub-folders to do this, I have so many to do that wouldnt be practical which is why im hoping to be able to flatten them.

You could turn on flat view (mixed, no folders), then select all and drag to the file display background to move everything to the main folder. That's what I tend to do.

Or put my old DirFlatten tool on a button:

cd {sourcepath$}
"C:\Path\To\DirFlatten.exe"

Or there's an Opus-only solution from Move all subfolder files to current folder - #9 by MNeMiC which essentially automates my first suggestion:

SET flatview=MixedNoFolders
SELECT ALLFILES
COPY MOVE HERE FLATVIEWCOPY=single
SET flatview=off

(I haven't tried that but it looks like it should work.)

Of course, be careful and try things out in a test folder a few levels deep in case it doesn't work like you expect.

Hi Leo,

Thanks so much for the quick reply unfortunately it didnt work. I have the following structure:
Parent Folder1999/Sub 1/Sub 2/File1.txt
Parent Folder1998/Sub 1/Sub 2/File2.txt
Parent Folder1997/Sub 1/Sub 2/File3.txt

I need to move the txt files into their respective parent folder and delete the sub folders. I have several of these parent folders that need the txt files moved into them so I figured flattening them would make it easier so I dont have to click into 56 individual folders.

Is that a better description?

The script you sent would move all the flattened files into the current folders, not their respective parent folders.

If you just want to move selected files up one level in Flat View then I think Lxp gave you a command for that in the other thread you asked in:

If you're still stuck please start a new thread as it's confusing having it tacked on the end of other threads that are about slightly different things (or lots of different things).

1 Like

The first script is only doing half of the listed features for me: With files selected, yes, it moves them into a new folder (still want to figure out how to pre-fill the name box with the first selected file's name), but when I have nothing selected it does nothing at all.

Is this expected given this was made for 11, or might I have done something wrong on my end?

1 Like

I've updated the root post so the case where nothing is selected works in Opus 12. It'll also use the name of the first file as the default folder name now.

1 Like

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.