1.

Solve : Logging a folders content size??

Answer»

I am looking for a way to log a folders content size such as C:\squid\var\cache for the Cache folder to log the size of the Cache storage. I was thinking I could use DIR and a switch to output the size, and Icant remember how I did it a long ways back. Would be nice to export the echo from the command for the folder size to a log file such as below, when executed from C:\squid\var\cache\

Fri 10/30/2009 at 11:43:01.28 Cache Folder is 124,656,576 bytes

The Cache folder has a bunch of sub DIRECTORIES that are stumping me on how to extract the size of the folder contents since DIR normally shows the local file content size, then the whole for the system below that, WITHOUT the properties of the local folder and sub-directories CONTAINED within it.


I know that the batch will be something like below where "DIR" will NEED to have something else done with it to get the output required. So looking for expert help where I am stumped. Maybe DIR isnt the way to handle this

@echo. %date% at %time% Cache Folder is >>CacheSize.log
DIR>>CacheSize.Log

[Saving space, attachment deleted by admin]Quote from: DaveLembke on October 30, 2009, 09:51:29 AM


DIR normally shows the local file content size, then the whole for the system below that, without the properties of the local folder and sub-directories contained within it.


Executed from a folder, Dir shows the names of any subfolders, and the names, dates and sizes of any files present in the folder, and the total size in bytes of the files in the folder only.

S:\Test\Batch>dir
Volume in drive S is USBHD
Volume Serial Number is 2C51-AA7F

Directory of S:\Test\Batch

26/09/2009 20:46 <DIR> .
26/09/2009 20:46 <DIR> ..
28/10/2009 21:02 <DIR> After 07-09-09
07/09/2009 17:13 <DIR> Older
15/05/2009 06:52 <DIR> EditVS
15/05/2009 06:56 <DIR> sst26
27/05/2009 17:56 116 Finder.bat
26/09/2009 20:46 44 getp2.bat
18/09/2009 16:51 217 isfolder.vbs
15/09/2009 17:48 46 ddf.vbs
09/05/2009 07:56 78 rarhelp.bat
25/05/2009 18:58 37 dequote.vbs
23/06/2009 19:34 245 Edit3
7 File(s) 783 bytes <-----------------------------------------
6 Dir(s) 146,969,190,400 bytes free


Are you saying you want to know the amount of data in each subfolder?

Hello...Yes I want to know how much total combined within local folder Cache and subfolders. I added a screenshot to show the subdirectory structure. I was thinking that maybe a DIR would have to be run against each sub directory and the sum of the files within it passed to a variable for every sub-folder/directory then the variables all added up at the end to give the lump sum of all data contained within Cache as the physical size of that folder and its sub-folders. (( But there has to be an easier method I am thinking ))

[Saving space, attachment deleted by admin]Are you able (permitted) to use the Sysinternals du utility?

http://live.sysinternals.com/du.exe

if so I will rough out a batch file


see my sig (GNU tools). Download and use them. It includes du command, plus others such as find (that is way better than Windows own), stat, etc you can use to show you sizes of files and folders. Of course, only if you are allowed to.Hello Salmon...sure I am sys admin and can run that. So if you can show a way to use DU and do that, that would be awesome. just type du c:\ for example on the command prompt. if you want, use a for loop to grab results. simple as that.Quote from: gh0std0g74 on October 31, 2009, 02:14:39 AM
just type du c:\ for example on the command prompt. if you want, use a for loop to grab results. simple as that.

Yes indeedy. Play around to get the syntax clear. Du /? to see help, where the various switches available are explained.

(I am using the Sysinternals du.exe)

Code below shows:

You can use the -q switch to prevent the Sysinternals copyright message (which, incidentally, if enabled echos to stderr not stdout)

I use quotes around folder names as good practice in case of spaces

Can pipe through Find "Size:" to get the line with file size

Comma separated file(s) size in bytes is 2nd token in that line

Remove commas from size to make suitable for set /a

Code: [Select]set dirname=C:\squid\var\cache
for /f "tokens=1-2" %%A in ('du -q "%dirname%" ^| find "Size:"') do set foldersize=%%B
set foldersize=%foldersize:,=%
i would recommend the GNU version since it has more capabilities and more or less works on a *nix with GNU as well.The Sysinternals version is simpler to manipulate (I have both) but as you say the GNU version is less limited (no commas in output. Another thing to consider might be DIRUSE from the NT Resource Kit

http://support.microsoft.com/kb/927229


Code: [Select]D:\Audio-DL>diruse /s "Amaral Discografia"

Size (b) Files Directory
23503006 1 AMARAL DISCOGRAFIA
45934192 13 AMARAL DISCOGRAFIA\Amaral
216104622 46 AMARAL DISCOGRAFIA\split-IOtest
73095739 13 AMARAL DISCOGRAFIA\Una Peque±a Parte del Mundo
358637559 73 SUB-TOTAL: AMARAL DISCOGRAFIA

358637559 73 TOTAL: AMARAL DISCOGRAFIA

D:\Audio-DL>diruse /s "Amaral Discografia" | find "TOTAL:"
358637559 73 SUB-TOTAL: AMARAL DISCOGRAFIA
358637559 73 TOTAL: AMARAL DISCOGRAFIA

D:\Audio-DL>diruse /s "Amaral Discografia" | find "TOTAL:" | find /V "SUB-TOTAL:"
358637559 73 TOTAL: AMARAL DISCOGRAFIA
Code: [Select]D:\Audio-DL>du -v "Amaral Discografia"

Du v1.31 - report directory disk usage
Copyright (C) 2005-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

44,857 D:\Audio-DL\amaral discografia\Amaral
211,039 D:\Audio-DL\amaral discografia\split-IOtest
71,382 D:\Audio-DL\amaral discografia\Una Peque±a Parte del Mundo
350,231 D:\Audio-DL\amaral discografia

Totals:
Files: 73
Directories: 3
Size: 358,637,559 bytes
Size on disk: 358,637,559 bytes
Code: [Select]D:\Audio-DL>gnuDU -b -c "Amaral Discografia"
45934192 Amaral Discografia/Amaral
216104622 Amaral Discografia/split-IOtest
73095739 Amaral Discografia/Una Peque±a Parte del Mundo
358637559 Amaral Discografia
358637559 total

D:\Audio-DL>gnuDU -b -c "Amaral Discografia" | find "total"
358637559 total

Cool... Thanks for your help guys. Going to play with it and learn it.Quote from: Salmon Trout on October 31, 2009, 03:41:14 AM
The Sysinternals version is simpler to manipulate (I have both) but as you say the GNU version is less limited. Another thing to consider might be DIRUSE from the NT Resource Kit

http://support.microsoft.com/kb/927229


Code: [Select]D:\Audio-DL>diruse /s "Amaral Discografia"

Size (b) Files Directory
23503006 1 AMARAL DISCOGRAFIA
45934192 13 AMARAL DISCOGRAFIA\Amaral
216104622 46 AMARAL DISCOGRAFIA\split-IOtest
73095739 13 AMARAL DISCOGRAFIA\Una Peque±a Parte del Mundo
358637559 73 SUB-TOTAL: AMARAL DISCOGRAFIA

358637559 73 TOTAL: AMARAL DISCOGRAFIA

D:\Audio-DL>diruse /s "Amaral Discografia" | find "TOTAL:"
358637559 73 SUB-TOTAL: AMARAL DISCOGRAFIA
358637559 73 TOTAL: AMARAL DISCOGRAFIA

D:\Audio-DL>diruse /s "Amaral Discografia" | find "TOTAL:" | find /V "SUB-TOTAL:"
358637559 73 TOTAL: AMARAL DISCOGRAFIA
Code: [Select]D:\Audio-DL>du -v "Amaral Discografia"

Du v1.31 - report directory disk usage
Copyright (C) 2005-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

44,857 D:\Audio-DL\amaral discografia\Amaral
211,039 D:\Audio-DL\amaral discografia\split-IOtest
71,382 D:\Audio-DL\amaral discografia\Una Peque±a Parte del Mundo
350,231 D:\Audio-DL\amaral discografia

Totals:
Files: 73
Directories: 3
Size: 358,637,559 bytes
Size on disk: 358,637,559 bytes
Code: [Select]D:\Audio-DL>gnuDU -b -c "Amaral Discografia"
45934192 Amaral Discografia/Amaral
216104622 Amaral Discografia/split-IOtest
73095739 Amaral Discografia/Una Peque±a Parte del Mundo
358637559 Amaral Discografia
358637559 total

D:\Audio-DL>gnuDU -b -c "Amaral Discografia" | find "total"
358637559 total


Quote from: Salmon Trout on October 30, 2009, 11:01:42 AM
Executed from a folder, Dir shows the names of any subfolders, and the names, dates and sizes of any filespresent in the folder, and the total size in bytes of the files in the folderonly.

S:\Test\Batch>dir
Volume in drive S is USBHD
Volume Serial Number is 2C51-AA7F

Directory of S:\Test\Batch

26/09/2009 20:46 <DIR> .
26/09/2009 20:46 <DIR> ..
28/10/2009 21:02 <DIR> After 07-09-09
07/09/2009 17:13 <DIR> Older
15/05/2009 06:52 <DIR> EditVS
15/05/2009 06:56 <DIR> sst26
27/05/2009 17:56 116 Finder.bat
26/09/2009 20:46 44 getp2.bat
18/09/2009 16:51 217 isfolder.vbs
15/09/2009 17:48 46 ddf.vbs
09/05/2009 07:56 78 rarhelp.bat
25/05/2009 18:58 37 dequote.vbs
23/06/2009 19:34 245 Edit3
7 File(s) 783 bytes <-----------------------------------------
6 Dir(s) 146,969,190,400 bytes free


Are you saying you want to know the amount of data in each subfolder?


I bolded the text that the op wants. It seems that even though salmon put it in red, no one noticed. that part only shows the size in the CURRENT directory. how about the rest of the directories? you have to individually go into each directory under s:\test\batch and get those sizes and add them up. Extra coding, extra brain cells killed. Quote from: gh0std0g74 on November 01, 2009, 05:13:10 PM
that part only shows the size in the current directory. how about the rest of the directories? you have to individually go into each directory under s:\test\batch and get those sizes and add them up. Extra coding, extra brain cells killed.

Yes, I wrote a huge batch that went one level deep doing just that before I remembered I had du and diruse. You can even use xcopy in list mode but that is probably just as tedious as using dir.


Discussion

No Comment Found