# Solved: Need a directory list that includes folder size



## Tippex (Sep 22, 2014)

I need a directory list that gives both filesizes and foldersizes in the current (top level only folder).
A "DIR" command does list filesizes but for folders it just puts "DIR" instead of the size.

At the moment I have added a batch file to the context menu containing:

@echo off
dir /n "%CD%" > "%CD%\_directory_listing.txt"
@echo on

Which if I right-click on a folder (and choose to run my batch file) in the current directory I get a directory list generated containing the filenames and their sizes. I'd like the top level folder (tree) sizes too, to save me from having to individually right-clicking each folder, selecting properties and grabing their sizes from there.

It's all less than ideal as even without the folder sizes, I have to remove the "_directory_listing.txt" entry itself from the list and if there aren't any folders in the current directory I have to create a "New Folder" just so I can focus the context menu in the current folder.

The nearest solution I've found was the batch below but it goes digging down directory trees (I wanted the current directory only) and still doesn't give folder sizes. 

@echo off
goto :TopOfCode
rem With the following qualifiers, add an extra % prefix for use in batch
rem So, if we have %%a in our FOR command and which to use %~tI (so A replaces I)
rem Then use %%~ta (for date and time)
rem In our code, %%~ta %%a %%~za gives date:time /path/name size 
=======================================================================
:TopOfCode
for /F "delims=" %%a in ('dir "*.*" /a-d /b /s') do (
set "size=..............................%%~za"
call set ".%%size:~-30%%:%%a=%%~ta %%a %%~za"
)
(for /F "tokens=1* delims==" %%a in ('set .^|sort /r') do echo %%b bytes) >List.txt

I wondered if the following batch file might give a clue how to get folder sizes but if left to process *.* it just totals up the whole of the current folder. If it could be called as subroutine and supplied individual files and folders instead of just *.* then I think it could be a possible solution.

Any ideas please?


----------



## foxidrive (Oct 20, 2012)

To find the filesizes and total in the current folder, try this: 

```
dir|findstr ": File(s)"|find /v ">" >"list.txt"
```


```
Directory of d:\Backup\Files\Util\xvi
05/09/1999  17:13               896 doswin.xct
07/09/1999  20:24             1,246 ebcdewin.xct
07/09/1999  20:24             1,232 ebcuswin.xct
26/06/2012  15:29             7,444 readme.txt
05/09/1999  17:13               896 windos.xct
07/09/1999  20:24             1,246 winebcde.xct
07/09/1999  20:24             1,232 winebcus.xct
26/06/2012  16:56           884,736 xvi32.exe
09/04/2011  15:07            75,183 XVI32U.chm
15/08/2001  11:21             1,266 xvi32u.cnt
09/04/2011  15:07            99,276 xvi32u.hlp
              11 File(s)      1,074,653 bytes
```
Give an example of what you want if it is not good enough.


----------



## Tippex (Sep 22, 2014)

foxidrive said:


> To find the filesizes and total in the current folder, try this:
> 
> ```
> dir|findstr ": File(s)"|find /v ">" >"list.txt"
> ...


Thank for your response.

I tried it out in a folder which a DIR shows file/folder details as:

14/07/2009 02:40 19,456 CbsApi.dll
14/07/2009 02:40 28,672 CbsMsg.dll
22/09/2014 16:36 Editions
22/09/2014 16:36 en-US
22/09/2014 16:36 GC64
22/09/2014 16:38 296 list.txt
22/09/2014 16:37 Packages
22/09/2014 16:37 Sessions
14/07/2009 03:35 SQM
21/11/2010 04:24 194,048 TrustedInstall
22/09/2014 16:37 Version
14/07/2009 02:41 12,288 wrpintapi.dll

but for which I need it to show file/folder details as:

14/07/2009 02:40 19,456 CbsApi.dll
14/07/2009 02:40 28,672 CbsMsg.dll
22/09/2014 16:36 308,707 Editions
22/09/2014 16:36 18,432 en-US
22/09/2014 16:36 49,664 GC64
22/09/2014 16:38 296 list.txt
22/09/2014 16:37 47,327,214 Packages
22/09/2014 16:37 6,511,988 Sessions
14/07/2009 03:35 0 SQM
21/11/2010 04:24 194,048 TrustedInstall
22/09/2014 16:37 8,192 Version
14/07/2009 02:41 12,288 wrpintapi.dll

(I had to manual add in the folder sizes from Windows Explorer Properties on each folder listed)

The file/folder details found using dir|findstr ": File(s)"|find /v ">" >"list.txt" were:

14/07/2009 02:40 19,456 CbsApi.dll
14/07/2009 02:40 28,672 CbsMsg.dll
21/11/2010 04:24 194,048 TrustedInstaller.exe
14/07/2009 02:41 12,288 wrpintapi.dll

It appears to ignore the folders and their sizes.

If DIR does not show individual folder (tree) sizes, then I guess findstr won't help.


----------



## foxidrive (Oct 20, 2012)

This isn't quite what you want - but will it do? It lists the folders first and then the files inside notepad.


```
@echo off
type nul>"%temp%.\total.txt"
for /f "delims=" %%a in ('dir /a:d /o:n /b /-p') do call :next "%%a"
echo(>>"%temp%.\total.txt"
dir|findstr ": File(s)"|find /v ">" >>"%temp%.\total.txt"
start "" notepad "%temp%.\total.txt"
GOTO:EOF
:next
for /f "delims=" %%b in ('
dir %1 /s /-p ^|findstr "File(s)"') do set "total=%%b"
echo >>"%temp%.\total.txt" %total% - %1
```


----------



## Tippex (Sep 22, 2014)

foxidrive said:


> ```
> @echo off
> type nul>"%temp%.\total.txt"
> for /f "delims=" %%a in ('dir /a:d /o:n /b /-p') do call :next "%%a"
> ...


Thank you very much!
Yes, the folder sizes are coming out.
Is there any way to add the date and timestamps for the folders?

7 File(s) 308,707 bytes - "Editions"
2 File(s) 18,432 bytes - "en-US"
1 File(s) 49,664 bytes - "GC64"
2379 File(s) 47,327,214 bytes - "Packages"
150 File(s) 6,511,988 bytes - "Sessions"
0 File(s) 0 bytes - "SQM"
2 File(s) 18 bytes - "Version"
23/09/2014 10:24 376 0_folder_file_list.bat
14/07/2009 02:40 19,456 CbsApi.dll
14/07/2009 02:40 28,672 CbsMsg.dll
22/09/2014 16:38 296 list.txt
21/11/2010 04:24 194,048 TrustedInstaller.exe
14/07/2009 02:41 12,288 wrpintapi.dll


----------



## foxidrive (Oct 20, 2012)

Here is a simple way to give you the data based upon the previous code:


```
@echo off
type nul>"%temp%.\total.txt"
for /f "delims=" %%a in ('dir /a:d /o:gn /b /-p') do call :next "%%a"
echo(>>"%temp%.\total.txt"
dir /o:gn|findstr ": File(s)"|find /v "<DIR>          ." >>"%temp%.\total.txt"
start "" notepad "%temp%.\total.txt"
GOTO:EOF
:next
for /f "delims=" %%b in ('
dir %1 /s /-p ^|findstr "File(s)"') do set "total=%%b"
echo >>"%temp%.\total.txt" %total% - %1
```


----------



## Tippex (Sep 22, 2014)

foxidrive said:


> ```
> @echo off
> type nul>"%temp%.\total.txt"
> for /f "delims=" %%a in ('dir /a:d /o:gn /b /-p') do call :next "%%a"
> ...


Thank you, indeed I now have the data and a single column copy & paste can achieve exactly what I'm after! :up: 

 7 File(s) 308,707 bytes - "Editions"
 2 File(s) 18,432 bytes - "en-US"
1 File(s) 49,664 bytes - "GC64"
2379 File(s) 47,327,214 bytes - "Packages"
150 File(s) 6,511,988 bytes - "Sessions"
0 File(s) 0 bytes - "SQM"
2 File(s) 18 bytes - "Version"
22/09/2014 16:36 Editions
22/09/2014 16:36 en-US
22/09/2014 16:36 GC64
22/09/2014 16:37 Packages
22/09/2014 16:37 Sessions
14/07/2009 03:35 SQM
22/09/2014 16:37 Version
23/09/2014 11:21 398 0_folder_file_list.bat
14/07/2009 02:40 19,456 CbsApi.dll
14/07/2009 02:40 28,672 CbsMsg.dll
22/09/2014 16:38 296 list.txt
21/11/2010 04:24 194,048 TrustedInstaller.exe
14/07/2009 02:41 12,288 wrpintapi.dll


----------

