Move marked files to folders according to their endings

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?

Yes. Just add the folder(s) to the TO= part(s) in your script. No slowdown :slight_smile:

If I add TO="' + folder + '/JPEG/\\0"'; Then How define the Other File Types?
like If I want to Move All .png files to Pictures/PNG folder and All .psd file should Move in to Pictures/PSD folder. then how to write that? If you have time then plz show us the way!

my other solution is add the Sub folder name in to the very first variable
var Folders = { "Pictures/JPEG": [ "jpg" ], "Pictures/PNG": [ "png" ], }
and it's work

i think this is the only logical and easiest way.... or is there something better?

You could use the extensions in the TO path, as an alternative.

It's scripting. You can do whatever you want, really. Use whatever works best for how you want it to function.

Please write some example code; make us better understood