?
?
Group and list all size of certain type.
Moderator: DosItHelp
-
- Posts: 2
- Joined: 03 May 2018 09:23
Group and list all size of certain type.
Last edited by LuigiKraken on 11 May 2018 09:45, edited 2 times in total.
Re: Group and list all size of certain type.
The working directory can be changed using CD or CD /D. E.g.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
Code: Select all
cd /d "C:\somewhere"
If you want to redirect the ECHO outputs then you may append a >>"%mypath%\output.txt" to every ECHO command line.
Steffen
-
- Posts: 2
- Joined: 03 May 2018 09:23
Re: Group and list all size of certain type.
Thanks this was very helpfull.
Re: Group and list all size of certain type.
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.With this you'd either:
(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)
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"
- replace %~1 with your target directory.
(do not touch the doublequotes)
- send your target directory as an argument to the script.
(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)