Move marked files to folders according to their endings

Hi...

Is there a possibility to move marked files to new folders according to their endings?
e.g. several jpg, txt and exe are marked and then these are moved into newly created folders (txt, jpg, exe). or maybe jpg, png, bmp etc. in "Pictures" and txt, odt, doc in "Documents"? is it possible to realize this by (internal) commands?

Thank you :smiley:

1 Like

Custom Copy MOVE FILTER command not moving folder may help you
.

just all ways do a test on a copy of files in case things don't work out

The Rename command (or dialog) can move files around based on their extensions (or file type groups of any other criteria if you want).

This would move things into subfolders with the same names as their extensions:

Many thanks-

i tested something around....

Rename *.jpg TO bilder\*.jpg TYPE=files

thats my poor result....
is there a simpler way to rename jpg/png to Pictures\*.*
and txt/doc to Documents\*.*
and so on....?
or do I have to move all file extensions individually?

Thank you!

A rename script could use the file type group to do that.

If you want something easier to make (but maybe not as good), you could have a multi-line button where each line moves one extension into a specific directory, for the extensions you care about

Thank you!

but why is it not as good?

i will try and test a Little Bit araound :smiley:

It's not as good because you'd have to list each extension and the folder you want it to go into, instead of it being automatic.

(OTOH, it may also be better, if you want more control over exactly where things go and the names of the folders. Depends what you want and if it matches the file type groups that are already defined.)

I have now used the copy function - I found it more logical.
It works so far but I would like that all files are moved in the lister if no file is marked.... is that somehow possible?
and is the snippet so okay?

Copy MOVE FILTER *.(jpg|png) WHENEXISTS=rename HERE CREATEFOLDER "Bilder"
@filesonly

You an use @ifsel:... to run different commands depending on whether or not anything is selected.

Thank you for your fast reply!

@ifsel unfortunately I have not been able to find in the documentation...
I want the command to be applied to all files when nothing is selected.
and if files were marked the command should be applied only to these marked.

My mistake, I was thinking of @disablenosel which won't do what you want. (It would disable the button entirely.)

At the moment, you may need to use scripting if you want a button which does different things depending on the selection. Should be quite a simple script, though. The default script shows how to do all/most of the things you'd need here, and we can help if needed.

If you know Javascript or VBScript already, it should be easy. Create a new button and set the Function drop-down to script mode, and you'll get a default script with examples of how to do a bunch of things.

If you don't know any scripting, or do but need help with part of it, let us know and we can assist.

and i don't see any possibility to activate the button in the internal commands - so that the files are moved depending on the selection.

Unfortunately I have no idea about these script languages....
doesn't the execution speed suffer from the languages then?
This is interpreted only when clicked or?

Thank you

The speed of the languages doesn't really matter. They won't be doing much, and nothing time critical. Most of the time will be spent waiting for the filesystem to rename the files, no matter which method is used.

EDIT: Added fix for files matching multiple extensions.

Here's a simple script, where the scripting itself is as simple as possible:

function OnClick(clickData)
{
	var tab = clickData.func.sourcetab;
	var cmd = clickData.func.command;
	cmd.deselect = false; // Prevent automatic deselection

	if (cmd.files.count == 0)
	{
		cmd.AddFiles(tab.files);
	}

	cmd.AddLine('Rename TYPE=files WHENEXISTS=rename REGEXP PATTERN=".+\\.(jpg|png)$" TO="Pictures/\\0"');
	cmd.AddLine('Rename TYPE=files WHENEXISTS=rename REGEXP PATTERN=".+\\.(txt|doc|pdf)$" TO="Documents/\\0"');
	cmd.Run();
}

Here's a slightly more complex script which does the same thing, but gives you a nice, easy-to-edit list of directories and extensions at the top:

var Folders =
{
	"Pictures":  [ "jpg", "png" ],
	"Documents": [ "doc", "txt", "pdf" ],
};

function OnClick(clickData)
{
	var tab = clickData.func.sourcetab;
	var cmd = clickData.func.command;
	cmd.deselect = false; // Prevent automatic deselection

	if (cmd.files.count == 0)
	{
		cmd.AddFiles(tab.files);
	}

	for (var folder in Folders)
	{
		var pattern = ".+\\.(";
		var extensions = Folders[folder];
		for (var i in extensions)
		{
			if (i != 0)
				pattern += "|";
			pattern += extensions[i];
		}
		pattern += ")$";
		var cmdLine = 'Rename TYPE=files WHENEXISTS=rename REGEXP PATTERN="' + pattern + '" TO="' + folder + '/\\0"';
		cmd.AddLine(cmdLine);
	}
	cmd.Run();
}

Same script as a .dcf file that's easier to add to your toolbar:

2 Likes

Wow - it works like a charm :smiley:
wonderful!.

Thats the best support i ever recived

big thanks!

  • i hope DOPUS will never die
2 Likes

Oh
I have found an little bug..
if a file has two file extensions that want to be filtered then there is an error message.
e.g. test.py.zip

Change this line:

pattern += ")";

To this:

pattern += ")$";
1 Like

Yes - thats it!

many thanks Leo :smiley:

1 Like

Now everything works great and as it should be. but would it also be possible to add subfolders?
e.g. create a subfolder named "Jpeg" in the Pictures folder and move the respective files there?

or will it slowdown the script too much?