Group and list all size of certain type.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
LuigiKraken
Posts: 2
Joined: 03 May 2018 09:23

Group and list all size of certain type.

#1 Post by LuigiKraken » 03 May 2018 09:26

?
































?
Last edited by LuigiKraken on 11 May 2018 09:45, edited 2 times in total.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Group and list all size of certain type.

#2 Post by aGerman » 03 May 2018 09:45

The working directory can be changed using CD or CD /D. E.g.

Code: Select all

cd /d "C:\somewhere"
Place this command below of setting the mypath variable.
If you want to redirect the ECHO outputs then you may append a >>"%mypath%\output.txt" to every ECHO command line.

Steffen

LuigiKraken
Posts: 2
Joined: 03 May 2018 09:23

Re: Group and list all size of certain type.

#3 Post by LuigiKraken » 04 May 2018 04:04

Thanks this was very helpfull.

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Group and list all size of certain type.

#4 Post by Compo » 04 May 2018 04:42

Luigi, it is rude and disengenuous, to pretend that someone elses code is yours, especially when that person is also a senior member here too!

Had you used and accepted, my answer, there was a particular place to add your directory, and it also outputted to a text file according to your question.

Here it is replicated below:

I would suggest that this task is less than simple for somebody new to batch scripting and will offer a solution which leverages PowerShell instead.

Code: Select all

@Echo Off
Set "MyDir=%~1"
If Defined MyDir CD /D "%MyDir%" 2>Nul || Exit /B
Dir /B/A-D >Nul 2>&1 || Exit /B
(For /F "Skip=3 Tokens=1-2 Delims=. " %%A In ('PowerShell -NoP -NoL^
 "GCI -Ex 'lists.txt' -Fo|?{!$_.PSIsContainer}|Group Extension|"^
 "Select Name,@{n='TS';e={(($_.Group|Measure Length -Sum).Sum)}}"
') Do Echo %%A %%B bytes)>"%__CD__%lists.txt"
With this you'd either:
  • replace %~1 with your target directory.
    (do not touch the doublequotes)
or:
  • send your target directory as an argument to the script.
If neither are done, it should produce output for the current directory.

(Please note that because the output file overwrites any existing one in the target directory it would include an old size of itself in its own results. For this reason I have added an exclusion, (untested), as part of the PowerShell commands)

Post Reply