Suffix: number of subfolders

Hi....

I am looking for a button....
this should create me a suffix at the folder...

would like to have the number of subfolders (not recursive) attached to the folder.

so like this:

Folder\1
Folder\2
Folder\3
Folder\4\256
Folder\5
Folder\6
Folder\7
Folder\8\9
Folder\10\24656

... turns into:

Folder+9\*.*

is this easy and simple to do?

thanks a lot

I don't understand the description of what you want, sorry.

Could you give some before and after examples of individual folders?

Something like this?

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

function OnGetNewName(getNewNameData) {
    return getNewNameData.item.is_dir ? getNewNameData.newname + '+' + fso.GetFolder(getNewNameData.item).SubFolders.count : false;
}

39876.orp (470 Bytes)

1 Like

Yes - that is what i mean :smiley:
it would be nice if no suffix when subfolder=0

and how integrate it as a button? or just copy & paste?

many thanks and sorry for my bad explanation

Sure :slight_smile:

// https://resource.dopus.com/t/suffix-number-of-subfolders/39876

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

function OnGetNewName(getNewNameData) {
    var item = getNewNameData.item;
    if (!item.is_dir) return false;
    var k = fso.GetFolder(item).SubFolders.count;
    return k > 0 ? getNewNameData.newname + '+' + k : false;
}

39876b.orp (596 Bytes)

https://resource.dopus.com/t/how-to-use-rename-presets-from-this-forum/26726

Super. Thank you very much...

i have an another question...
how to write the script if i want to only count all subfolders (recursiv too) that include files?

dont count empty folders (or folders with empty folders in it)

thanks again - big thanks :smiley:

Here you go.

// https://resource.dopus.com/t/suffix-number-of-subfolders/39876

var fsu = DOpus.FSUtil();
var fso = new ActiveXObject('Scripting.FileSystemObject');

function OnGetNewName(getNewNameData) {
    var item = getNewNameData.item;
    if (!item.is_dir) return false;
    // var k = fso.GetFolder(item).SubFolders.count;
    var k = CountNonEmptySubFolders(item);
    return k > 0 ? getNewNameData.newname + '+' + k : false;
}

function CountNonEmptySubFolders(dir) {
    var k = 0;
    var folderEnum = fsu.ReadDir(dir, 'r');
    while (!folderEnum.complete) {
        var folderItem = folderEnum.Next();
        if (!folderItem.is_dir) continue;
        if (fso.GetFolder(folderItem).size == 0) continue;
        k++;
    }
    return k;
}

39876c.orp (1007 Bytes)

1 Like

Thank you. the rename script works fine - just as I wanted.
Thanks for that :smiley:

but unfortunately i can't get it to work as a button :frowning:

There are three options in

Using a Rename Preset outside the Rename Dialog

https://resource.dopus.com/t/how-to-use-rename-presets-from-this-forum/26726

Which one is giving you troubles?

26.11.2021 00:34 Fehler in Zeile 2, Position 8
26.11.2021 00:34 Option Explicit
26.11.2021 00:34 ^
26.11.2021 00:34 ';' erwartet (0x800a03ec)
26.11.2021 00:34 Parsefehler - Skript abgebrochen

want to put everything in a button without preset... but everything fails :frowning:

Show us what you're doing and we can tell you what's wrong with it.