Hi,
I want to log certain directories’ size evolution. For example, I’d like to have a program grab “c:hello”‘s size every day at 7:00 pm and log it to a TXT file with proper date/time identification.
Any thoughts?
Thank you in advance
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Questions: Browsers and desktop software » Other desktop and Microsoft Store software » Directory Size Logger
Have a look at Karen’s Directory Printer. It is for personal use and inexpensive for business use.
Joe
--Joe
If you would be prepared to schedule a BATch file, it is fairly simple!
@echo off :: DIRSIZE - determine size of a directory :: the directory path must be supplied as a parameter :: preceded and followed by double quotes if there is a blank in the path :: e.g. C:windows or "C:Documents and SettingsAll Users" if .%1==. echo %~n0: no directory name was supplied & pause & goto :eof if not exist %1 echo %~n0: directory %1 does not exist & pause & goto :eof echo %~n0: determining size of %1 ... setlocal :: generalised DATE and TIME routine for NT4/W2K/WXP and all Regional Settings :: date variable %yy% has four digits, 20nn, and %mm%, %dd%, have two each :: time variables %hr%, %mn%, %sc% and %th% each contain two digits if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4) for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do ( for /f "tokens=%toks% delims=.-/ " %%e in ('date /t') do ( for /f "tokens=5-8 delims=:., " %%i in ('echo.^|time') do ( (set %%a=%%e) & (set %%b=%%f) & (set %%c=%%g) & rem create yy, mm, dd (set hr=%%i) & (set mn=%%j) & (set sc=%%k) & (set th=%%l) rem note the variable names for Time: hr, mn, sc, th ))) if 1%yy% LSS 200 (set yy=20%yy%) & :: ensure 4-digit years in %yy% if 1%hr% LSS 20 (set hr=0%hr%) & :: ensure 2-digit hours in %hr% :: do the DIR command for the directory name passed :: and extract the size occupied by all the files :: from the line mmm File(s) nnnnnnn bytes for /f "tokens=3" %%a in ('dir /-c %1 ^| find "File(s)"') do set dirsize=%%a :: right-justify the byte value in a 15-character field (allowing up to 999 GB) set dirsize= %dirsize% set dirsize=%dirsize:~-15% :: write date, time, directory path, directory size :: to the screen and to the log file .txt echo %yy%/%mm%/%dd% %hr%:%mn% %1 %dirsize% echo %yy%/%mm%/%dd% %hr%:%mn% %1 %dirsize% >> %~n0.txt endlocal
Name it (say) DIRSIZE.BAT and the resulting log file will be named DIRSIZE.TXT.
Call it with the directory name/path
as DIRSIZE C:WINDOWS
or DIRSIZE “C:Documents and SettingsAll UsersApplication Data” (if the path should contain a blank)
John
Hi John,
Amazing! I didn’t expect you to type the code for me!
In fact I wouldn’t have been able to!
Your solution would be perfect, save for two things:
– for some reason it doesn’t log the folder size
– it logs the year incorrectly (but this is not a real problem, I can live with it).
I attach an example .txt file. JIC, the last entry’s date is in the yyyy-mm-dd format because by that time I’d realized how to change it and I feel more comfortable this way.
Below I copy the commands I used:
C:>dirsize.bat c:archivosalfabeta
DIRSIZE: determining size of c:archivosalfabeta …
20/03/22 11:21 c:archivosalfabeta
C:>dirsize.bat c:archivosalfabeta
DIRSIZE: determining size of c:archivosalfabeta …
20/03/22 11:24 c:archivosalfabeta
C:>dirsize.bat c:archivosalfabeta
DIRSIZE: determining size of c:archivosalfabeta …
20-03-22 11:25 c:archivosalfabeta
Any ideas why’d this happen?
Hi Diego,
One question: do you want the details put in a new file or appended to a file each time the code runs?
The basic code in VBScript to get size and time is fairly easy:
Dim fso, fdrSelected Set fso = CreateObject("Scripting.FileSystemObject") Set fdrSelected = fso.GetFolder(wscript.arguments(0)) msgbox Now & " : " & fdrSelected.Size
but the finer points depend on what you want to do with the ouput i.e. do you want it added to a log file or to create a new file each time?
OK then, a script like this should do:
Dim strLogFilePath strLogFilePath = "C:TestLogFile.txt" Dim fso, fdrSelected, tsmFileText Set fso = CreateObject("Scripting.FileSystemObject") Set fdrSelected = fso.GetFolder(wscript.arguments(0)) Set tsmFileText = fso.OpenTextFile(strLogFilePath, 8, True) tsmFileText.WriteLine Now & " : " & fdrSelected.Size tsmFileText.Close Set tsmFileText = Nothing Set fso = Nothing
You can save it as, say, ListDirSize.vbs and then call it using ListDirSize C:FolderPath
You can change the path to the log file as necessary.
HTH
Ah – I had forgotten that you probably have a non-English version!
Could you go to a command prompt and type
DATE
and tell me what results, and
DIR
and tell me what results.
I am assuming that the DIR command gives as the second last line:
mmm File(s) nnnnnnn bytes
and am searching in the BATch file for the word “File(s)” to get the directory size from that line.
Thanks
John
Diegol
OK, your date command gives preceding words I have never encountered!
Final requests are to do, in a Command Prompt window:
ECHO %date%
ECHO %time%
(preferably before 10:00 in the morning!), and I should be able to simplify the timestamp code significantly.
For the DIR command, the line you have given me is the final line, which says how full the disk is, not the preceding line, which says how many files and how many bytes are in the specified directory!
Thanks
John
Your batch and VB scripts somehow inspired me. I recalled this little app called AutoIt and gave it a try.
This script lets me output several directories’ sizes to a matrix. The idea is to output to the CSV format so I can program the script to run, say, daily, and after some time (a couple months for example) open in Excel to analyze the data.
Here’s the code:
Note: I enclose the code in dashes because I’m having problems to use the supported Script font – not the first time!
———————————————————————————————————————————————-
#include
#include
$File = “SizeLogger.csv”
; FileExists returns 1 if file exists, 0 otherwise
$Exists = FileExists($File)
$Date = @mday & “/” & @mon & “/” & @year
$Time = @hour & “:” & @min
if $Exists = 1 then
; FileOpen returns a file handle if it succeeds, -1 otherwise
$File= FileOpen ( $File, 1)
if $File -1 then
FileWriteLine ($File, $Date & “;” & $Time & “;” & dirgetsize(“Dir 1”) & “;” & dirgetsize(“Dir 2”) & “;” & dirgetsize(“Dir 3”))
Else
Msgbox(0, “Error”, “Could not open the specified file.”)
Endif
Else
_FileCreate($File)
FileWriteLine ($File, “Date” & “;” & “Time” & “;” & “Dir 1” & “;” & “Dir 2” & “;” & “Dir 3” )
FileWriteLine ($File, $Date & “;” & $Time & “;” & dirgetsize(“Dir 1”) & “;” & dirgetsize(“Dir 2”) & “;” & dirgetsize(“Dir 3”))
Endif
———————————————————————————————————————————————-
Replace Dir 1, Dir 2 and Dir 3 for directory paths of your choice and you can add more in a similar fashion (up to 256 columns if it’s to be viewed with Excel).
For the code to work, you’d have to save it to a plain file with AU3 extension, download Autoit and either install it (you can then run the AU3 file) or use the standalone compiler to generate an EXE file.
The
and
tags are relatively new additions that haven’t been included in the 1-Click TagPanel and help yet
There’s a reseource kit utility called “DIRUSE” http://www.microsoft.com/windows2000/techi…ng/diruse-o.asp%5B/url%5D that will output this. (You would have to look up the switches to get it to just print the totals. Then you could write a batch file that outputs to a file (e.g. “>> c:data.t”) and just run that from the scheduler.
That’s off the top of my head, though.
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications