Add # of pics to Folder Name

Hi all,

I would like to add the number of pics (or just contents) within a folder to be part of the folder's existing name:

Folder Names Before
Jim Smith in Florida 2014
Max Birthday Party 2013

Folder Names After
Jim Smith in Florida 2014 (25)
Max Birthday Party 2013 (57)

Ideally this can be accomplished with highlighting a folder name and renaming it . Any help would be greatly appreciated.

Thank you.

Rename PATTERN "*" TO "* {filecount}" FILEINFO TYPE=dirs

Should work, but does not work.
Maybe Leo could answer why {filecount} could be selected as fileinfo field in rename but would not bring the input.
Possible a bug.

I think you would have to use a button script or rename script to do this. The rename command won't count files in sub-folders by itself, but if it runs a script the script can do so pretty easily.

Oh, well creating a script is way out of my my league. :slight_smile: Can someone help me with this?

Here's a starting point for you.

This only counts files directly below each folder. (Change ReadDir(GetNewNameData.item, False) from to use True at the end instead if you want it to be recursive.)

It counts all files, but if you want it to only count files with specific extensions that's easy enough to add.

If the folder name already has a count, it will be removed and replaced by the new count.

[code]@script vbscript
Option Explicit

Dim re
Set re = New RegExp
re.Pattern = "^(.*)( (\d))$"

Function OnGetNewName ( ByRef GetNewNameData )
Dim folderEnum, folderItem, fileCount, matches
If (GetNewNameData.item.is_dir) Then
' Count files in folder.
fileCount = 0
Set folderEnum = DOpus.FSUtil.ReadDir(GetNewNameData.item, False)
Do While (Not folderEnum.complete)
Set folderItem = folderEnum.Next
If (Not folderItem.is_dir) Then
fileCount = fileCount + 1
End If
Loop
' Return new name.
' If the name already has a count at the end, remove it first.
Set matches = re.Execute(GetNewNameData.newname)
If (matches.Count > 0) Then
OnGetNewName = matches(0).Submatches(0) & " (" & fileCount & ")"
Else
OnGetNewName = GetNewNameData.newname & " (" & fileCount & ")"
End If
End If
End Function[/code]


Whoo! Leo you helped out here, while I was busy putting some pieces together. So Leonard you have 2 "starting points" then. o)

You might try the command I created especially for this purpose, I didn't think of a rename script somehow, but a command should do equally well.
The only thing it does not (yet?), compared to Leos solution, is removing an already existing number from the foldername.

Thank you very much Leo & tbone. Both methods work like a charm.