Unable to undo all items renamed via cmd.Run at once

I selected two folders for testing, and finally I can only revoke a random file. Is this an issue? Is there any other way?

    var tab = DOpus.listers(0).activetab;
    var cmd = DOpus.Create().Command;
	var fsu = DOpus.FSUtil;
    var dirs = tab.selected_dirs;

if (dirs.count != 0) {
	cmd.ClearFiles();
    for (var eSel = new Enumerator(dirs); !eSel.atEnd(); eSel.moveNext() )
    {
		var eFolder = eSel.item();
		var folderEnum = fsu.ReadDir(eFolder);
	    while (!folderEnum.complete) {
		    var item = folderEnum.Next;
		    if (item.is_dir) {
			    var sFolderEnum = fsu.ReadDir(item, "r");
				while (!sFolderEnum.complete) {
				    var sItem = sFolderEnum.Next;
					if (!sItem.is_dir) {
					    cmd.AddLine('Rename "' + sItem + '" TO="' + eFolder + '\\' + sItem.name + '" AUTORENAME')
						DOpus.Output('Rename "' + sItem + '" TO="' + eFolder + '\\' + sItem.name + '" AUTORENAME')
					}
				}
			}
	    }
	}
	cmd.Run
}

image

I tested another method and the same thing:

You're running a separate Rename command on each item, so there will be separate undo entries for each item.

Is there a way to rename all items to different paths at once?

Yes, a few ways.

The easiest would be to use a Rename Script (i.e. the Rename command runs the script, instead of the other way around, and all the script does is tell it the new name/path for each folder).

It seems that this way cannot use script first? I need the script to enumerate files in subfolders.

Rename can be recursive, if that's what you need.

If you want to do it the other way around, add all the things you want to rename to the Command object (e.g. via ClearFiles, AddFiles) and then run the rename command on that. If needed, it can specify a Rename Preset which includes a script with further logic (e.g. if you need to make different choices for different folders).

The topic is resolved, but it looks like there is no way to delete empty folders. :upside_down_face:
The undocumented command Rename PATTERN="*" TO="{filepath$}*" AUTORENAME RECURSE HERE works fine, I will continue to use it.

Which part is undocumented?

You can delete empty folders with the Delete command. Rename isn't the place to do that. :smiley:

HERE

Need to delete all empty folders at once, there doesn't seem to be a way to do this in a recursive rename script.

The Rename command doesn't have a HERE argument. That argument is undocumented because it doesn't exist. The command is really being parsed as RECURSE=HERE which is the same as RECURSE=AnyRandomString which is the same as just having RECURSE there.

The Rename command isn't the thing to use for deleting things.