Rename files with random alphanumeric characters

You're absolutely right, I'm going to correct that detail, thank you very much!

I made a rename preset.
I don't know what I'll use it for, but I imagine someday I will find a perfect use for it and be very grateful I have it. Thanks !

I am the one who thanks!

1 Like

Stumbled over this thread - so far I am using rename based on a file list (with random characters).

This script might make it easier.
However, i got this error

"

 21-03-2025 11:21  Successfully initialized 'JScript' engine
 21-03-2025 11:21  Error at line 1, position 8
 21-03-2025 11:21  Rename PATTERN * TO *
 21-03-2025 11:21         ^
 21-03-2025 11:21  Expected ';' (0x800a03ec)
 21-03-2025 11:21  Parse error - script aborted

"
Using the script dtd aug.27 2023 (i.e. last one)

What am I supposed to change?

Thanks.

Not JScript...

??

Ah, right.
Thanks!

The 2nd line confused me. Sorry.
Script works wonderful.

Thanks again.

Again, great script!
Wonder, would it be possible to change the script so it randomly renames both sub folders and files, this whilst selecting the parent folder.
Meaning: select folder: run script - any sub folders and files to be randomly renamed.

The script can do it, but one needs to expand folders and files in the right window panel, select them and then perform the rename.However, not just by selecting 1 parent folder.

If impossible or too complicated, forget it. Just asking.

Change
Rename PATTERN * TO *
To:
Rename PATTERN * TO * RECURSE
The folder will not be renamed.

Very sorry for the delay. One way or the other I didn't receive a notification of your response. Just now stumbled over your reply.

I have made the changes and indeed the files in sub folders are randomly renamed, but I could not get the sub folder names renamed.
FWIW - as a workaround - I created a separate preset (within "Rename") and checked "Rename files in selected sub-folders and Rename folders as well as their contents".
That seems to work.

Hi, try this script to see if it's what you want. Works with one or more selected folders. Selected folders are not renamed, only their contents. Try it on experimental files in case you encounter any errors.

Copy the code directly into a button in Script mode.

function OnClick(clickData) {
    var folders = clickData.func.sourcetab.selected_dirs;

    if (folders.count == 0) {
        DOpus.Output("Por favor selecciona una o más carpetas.");
        return;
    }

    var fso = new ActiveXObject("Scripting.FileSystemObject");

    // Acumulador de nombres usados globalmente
    var usedNames = {};

    // Función para generar nombre aleatorio único
    function getRandomName(ext) {
        var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // Caracteres que compondrán el nombre
        var name;
        do {
            name = "";
            for (var i = 0; i < 8; i++) { // 8 = Número de caracteres del nombre
                name += chars.charAt(Math.floor(Math.random() * chars.length));
            }
            name = ext ? (name + "." + ext) : name;
        } while (usedNames[name]);
        usedNames[name] = true;
        return name;
    }

    // Procesar cada carpeta seleccionada
    for (var f = 0; f < folders.count; f++) {
        var basePath = folders(f).realpath;
        var allItems = [];

        // Recorrer recursivamente la carpeta
        function recurse(path) {
            var folderEnum = DOpus.FSUtil.ReadDir(path, "r"); // Recursivo
            while (!folderEnum.complete) {
                var item = folderEnum.Next();
                if (item.is_dir) {
                    recurse(item.realpath);
                    allItems.push(item); // carpetas al final
                } else {
                    allItems.unshift(item); // archivos al inicio
                }
            }
        }

        recurse(basePath);

        // Renombrar archivos y carpetas
        for (var i = 0; i < allItems.length; i++) {
            var item = allItems[i];
            var parentPath = item.path;
            var ext = "";

            if (!item.is_dir && item.ext) {
                ext = item.ext.replace(/^\./, "");
            }

            var newName = getRandomName(ext);
            var newPath = parentPath + "\\" + newName;

            var cmd = clickData.func.command;
            cmd.ClearFiles();
            cmd.AddFile(item);
            cmd.RunCommand('Rename "' + item.realpath + '" TO="' + newPath + '"');
        }
    }

    DOpus.Output("Renombrado completo de todas las carpetas seleccionadas.");
}

Sorry for the late reply.
Thanks again for taking the time to try and find a solution.
The matter is already solved, as per my post before.
Tried above script, but it produced error (could not find file specified, or something like that).
Kept the "Esc' key pressed until it stopped.

Let it rest, dasota.. The first script is fine. Minor drawback: it can not be run from context menu or a button. So be it.

Thanks again.

What script can not be run from a button or a context menu?

Just a one-line to say THANKS again for this nice script. Am very often using it, followed by ForceDelete. It is really super.Thanks!

1 Like

I'm very glad to know this little script is helping you so much. I just published another script (Rename Max) (link) with more customizable options, such as replacing the entire name with random characters, whether alphabetic, numeric, or a combination of both (alphanumeric), and you can also specify the number of these characters.