Multi-Rename: get File count and rename folder with ?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
Alexisback
Junior Member
Junior Member
Posts: 80
Joined: 2016-10-26, 20:04 UTC

Multi-Rename: get File count and rename folder with ?

Post by *Alexisback »

Hello everyone

is this possible? (With plugins or other) :idea:
Count file in folder (with filter for photo, video, program, doc, etc) and rename folder with count number

Example folder with images:

Before
Folder

After
Folder (16 images)
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

Sure. Get DirSizeCalc plugin, install it, open MRT and use something like

Code: Select all

[N] ([=dirsizecalc.File Count])
See the "[=? Plugin]" button for other plugin fields and stuff.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Alexisback
Junior Member
Junior Member
Posts: 80
Joined: 2016-10-26, 20:04 UTC

Post by *Alexisback »

Hi Dalai

I've already installed this plugin

What I want to do is different :roll:

1) counting files within the folder
2) physically rename the folder with count results

example:

First the folder has this name
Folder

After counting (by content) rename the folder so
Folder (16 images)

ps:
The link to the plugin is wrong
download
http://lefteous.totalcmd.net/tc/dirsizecalc_eng.htm
forum topic
https://www.ghisler.ch/board/viewtopic.php?t=18021&postdays=0&postorder=asc&start=0&sid=17d1b5adb19b6221130aaa732cd8994c
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

PowerShell: rename folder with number of files inside

Post by *Stefan2 »

You can use your OS scripting tool to accomplish that:

PowerShell

- See your windowsTM start menu to launch PowerShellTM
- Navigate to your "main" folder.
(You can open a "DOS-Box" in TC and execute there the command Powershell to get a PoSh console in the right directory)

- Type or copy in this command line:
Get-ChildItem -Directory | ForEach-Object{ Rename-Item $_ ($_.Name + " ({0} Files)" -f (GCI $_\* -File -Include *.jpg,*.vbs,*.TXT).count) }

- maybe adjust it to your needs.

Explanations:
Rename-Item $_ ( ... ) will rename each processed folder with original Name plus " ({0} Files)"
where {0} is replaced by the math done with (GCI $_\* -File -Include *.jpg,*.vbs,*.TXT).count)
where GCI is short for Get-ChildItem.



For more info just ask
or see https://www.google.de/search?q=powershell+for+beginners


- - -


I have tested this by using abbreviated commands:

Command line
ls -Dir|%{ren $_ ($_.Name + " ({0} Files)" -f (ls $_\* -File -Inc *.jpg,*.vbs,*.TXT).count)}

Test folder 1 (0 Files)\
Test folder 2 (14 Files)\
Test folder 3 (0 Files)\
Test folder 4 (4 Files)\
Test folder 5 (4 Files)\
Test folder 6 (3 Files)\
Test folder 7 (21 Files)\
Test folder 8 (0 Files)\
Test folder 9 (0 Files)\
Test folder 10 (4 Files)\
Test folder 11 (4 Files)\
Test folder 12 (0 Files)\


- - -


To count files in sub sub-folders also, use
GCI $_\* -Recurse -Include

instead off
GCI $_\* -File -Include


So use:

Command line
ls -Dir|%{ren $_ ($_.Name + " ({0} Files)" -f (ls $_\* -Rec -Inc *.jpg,*.vbs,*.TXT).count)}


Test folder 1 (0 Files) (2 Files)\
Test folder 2 (14 Files) (14 Files)\
Test folder 3 (0 Files) (0 Files)\
Test folder 4 (4 Files) (4 Files)\
Test folder 5 (4 Files) (7 Files)\
Test folder 6 (3 Files) (6 Files)\
Test folder 7 (21 Files) (40 Files)\
Test folder 8 (0 Files) (3 Files)\
Test folder 9 (0 Files) (0 Files)\
Test folder 10 (4 Files) (16 Files)\
Test folder 11 (4 Files) (4 Files)\
Test folder 12 (0 Files) (0 Files)\

^^^ that is the result of two runs, one after the other ^^^




.
Last edited by Stefan2 on 2017-06-19, 10:08 UTC, edited 2 times in total.
Alexisback
Junior Member
Junior Member
Posts: 80
Joined: 2016-10-26, 20:04 UTC

Re: PowerShell: rename folder with number of files inside

Post by *Alexisback »

Stefan2 wrote:You can use your OS scripting tool to accomplish that:

PowerShell
.

Hi Stefan2

I do not know PowerShell

:oops: :oops: :? :roll:

How to make it work?
Do i have to create a file?

ps:sorry for my English
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

Alexisback wrote:What I want to do is different :roll:
Well, that depends on the folder's contents.
1) counting files within the folder
2) physically rename the folder with count results
I don't see any problem here, i.e. MRT can do that in conjunction with DirSizeCalc plugin.

To get this straight: DirSizeCalc can count files, and you can use this plugin (and any other content plugin) in MRT to rename the directories. It depends on whether or not you have other files in this directories, too. If you have only pictures in the directories you want to rename to "dir_name (X images)" you can use the method no problem. If you have other files, such as text, docs, etc in these directories as well, my method won't work well, because DirSizeCalc counts files regardless of their extension (file type).
ps:
The link to the plugin is wrong
No, it's not. It's another download source for this plugin, as it is for many other plugins.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Alexisback
Junior Member
Junior Member
Posts: 80
Joined: 2016-10-26, 20:04 UTC

Post by *Alexisback »

Dalai wrote:
Alexisback wrote:What I want to do is different :roll:
I don't see any problem here, i.e. MRT can do that in conjunction with DirSizeCalc plugin.
Hi Dalai

You're right, I did not read that i have to open MRT (my mistake) :)
This method works

The problem is this: :roll:

If there are 16 images in the folder and 2 different files (.txt, .doc)
I want it to count only 16 pictures (and rename the folder)

ps:
If I open this link to me by mistake

http://totalcmd.net/plugring/dirsizecalc.html

404 Not Found:
Not Found

The requested URL /plugring/dirsizecalc.html was not found on this server.

thanks
User avatar
tuska
Power Member
Power Member
Posts: 3740
Joined: 2007-05-21, 12:17 UTC

Post by *tuska »

Alexisback wrote:ps:
If I open this link to me by mistake
http://totalcmd.net/plugring/dirsizecalc.html

404 Not Found:
Not Found

The requested URL /plugring/dirsizecalc.html was not found on this server.
thanks
Try https://totalcmd.net/plugring/dirsizecalc.html (https://...
Post Reply