• Directory Size Logger

    Author
    Topic
    #430609

    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

    Viewing 2 reply threads
    Author
    Replies
    • #1006011

      Have a look at Karen’s Directory Printer. It is free for personal use and inexpensive for business use.

      Joe

      --Joe

      • #1006100

        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.

    • #1006039

      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

      • #1006103

        Hi John,

        Amazing! I didn’t expect you to type the code for me!
        whisper 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?

        • #1006113

          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?

          • #1006120

            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

            • #1006141

              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

            • #1006157

              It worked! Thanks!! cheers thumbup thankyou

        • #1006257

          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

          • #1006343

            You are right. Here go the results:

            – For the Date Command:
            C:Documents 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!

            • #1006470

              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

          • #1006448

            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.

            • #1006462

              The Script font is not meant for VBA or VBScript code – it is a handwriting font! It makes code virtually unreadable.
              You can put

              Code:
               and 

              tags around code if you want a non-proportional font, or

               and 

              tags if you want a non-proportional font and you want to preserve indentation etc.

            • #1006598

              Thanks Hans.

              I see the

               and 

              tags in the Markup Tags pop-up, but where would I have picked the

              Code:
               and 

              tags from? I wouldn’t have noticed them if you hadn’t told me. I couldn’t find them in the Help link either. scratch

            • #1006605

              The

              Code:
               and 

              tags are relatively new additions that haven’t been included in the 1-Click TagPanel and help yet sorry

            • #1006613

              No problem. Glad to see some new things going on thumbup.

            • #1006647

              If your going to use

              Code:
               and 

              tags for your code, then you will also need to include [tab] tags to indent lines. Easiest way is to paste the vba code into a word document and replace every instance of 4 spaces with [tab].

              StuartR

            • #1006651

              Thanks for the tip, I’ll keep it in mind!

    • #1006224

      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.

      • #1006382

        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).

    Viewing 2 reply threads
    Reply To: Directory Size Logger

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: