Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Directory Size Logger

    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
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  2. #2
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    23,585
    Thanks
    5
    Thanked 1,059 Times in 928 Posts

    Re: Directory Size Logger

    Have a look at Karen's Directory Printer. It is <img src=/S/free.gif border=0 alt=free width=30 height=15> for personal use and inexpensive for business use.

    Joe
    Joe

  3. #3
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Directory Size Logger

    If you would be prepared to schedule a BATch file, it is fairly simple!<pre>@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 "Cocuments 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 <batchfilename>.txt
    echo %yy%/%mm%/%dd% %hr%:%mn% %1 %dirsize%
    echo %yy%/%mm%/%dd% %hr%:%mn% %1 %dirsize% >> %~n0.txt
    endlocal</pre>

    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 "Cocuments and SettingsAll UsersApplication Data" (if the path should contain a blank)

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  4. #4
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Directory Size Logger

    Hi Joe,

    Thanks for that. It looks pretty good, but it logs way more information than I actually need.
    Even when I set it to only print minimal directory information and to ommit comments, it generates one line per subfolder and, if I ommit comments, it doesn't record the logging date.
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Directory Size Logger

    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:
    <pre> Dim fso, fdrSelected
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fdrSelected = fso.GetFolder(wscript.arguments(0))
    msgbox Now & " : " & fdrSelected.Size
    </pre>

    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?
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Directory Size Logger

    Hi John,

    Amazing! I didn't expect you to type the code for me!
    <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17> 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?
    Attached Files Attached Files
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  7. #7
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Directory Size Logger

    Hi rory,

    I'd like to append the output to a log file just like John's code does. See the attached in this post for an example log file (it would log the file size as well).

    Thanks
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Directory Size Logger

    OK then, a script like this should do:
    <pre>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
    </pre>

    You can save it as, say, ListDirSize.vbs and then call it using <code> ListDirSize C:FolderPath</code>
    You can change the path to the log file as necessary.

    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Directory Size Logger

    It worked! Thanks!! <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15> <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  10. #10
    5 Star Lounger
    Join Date
    May 2003
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    629
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Directory Size Logger

    There's a reseource kit utility called "DIRUSE" http://www.microsoft.com/windows2000/techi...ng/diruse-o.asp 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.

  11. #11
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Directory Size Logger

    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
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  12. #12
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Directory Size Logger

    You are right. Here go the results:

    - For the Date Command:
    Cocuments and SettingsPeru-014>date
    La fecha actual es: 23/03/2006
    Escriba la nueva fecha: (dd-mm-aa)

    - For the DIR command
    18 dirs 7.135.051.776 bytes libres

    Thanks!
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  13. #13
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Directory Size Logger

    Thanks, Jim.

    I like rory's script best for the way it logs data. But Diruse looks like a promising app too (it has a number of parameters that may prove useful).
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  14. #14
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Directory Size Logger

    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!

    ----------------------------------------------------------------------------------------------------------------------------------------------
    <font face="Script MT Bold">#include <file.au3>
    #include <date.au3>

    $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</font face=script>
    ----------------------------------------------------------------------------------------------------------------------------------------------

    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.
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Directory Size Logger

    The Script font is not meant for VBA or VBScript code - it is a handwriting font! It makes code virtually unreadable.
    You can put <!t>
    Code:
    <!/t> and <!t>
    <!/t> tags around code if you want a non-proportional font, or <!t>[pre]<!/t> and <!t>[/pre]<!/t> tags if you want a non-proportional font and you want to preserve indentation etc.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •