Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: batch script to monitor folder size  (Read 5105 times)

0 Members and 1 Guest are viewing this topic.

masterwix

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 7
    batch script to monitor folder size
    « on: March 02, 2016, 02:36:03 AM »
    Hello
    i trying to make a script to monitor the size folder every hour and cant :
    any help will apreciated.

    i need something like this:

    script one:
    1-chek the actual size of the folder and write the size to a txt file.(in a remote pc like: \\pc2\folder1  )

    script two
    2-read the file size from the txt and compare with the actual folder size , if size was changed - close the script.
    if size not changed open url.

    why 2 scripts ? because i want to use the windows schedule,.
    thank you very much!

    zask



      Intermediate

      • Experience: Experienced
      • OS: Other
      Re: batch script to monitor folder size
      « Reply #1 on: March 24, 2016, 05:56:30 PM »
      Here you go.

      The first file is named "FileSize.bat"

      @echo off
      setLocal EnableDelayedExpansion
      set /a value=0
      set /a sum=0
      FOR /R %1 %%I IN (*) DO (
      set /a value=%%~zI/1024
      set /a sum=!sum!+!value!
      )
      echo !sum! > Size.txt
      pause

      The file makes a text file named "size.txt"

      The second file is name "Compare.bat"

      @echo off
      setLocal EnableDelayedExpansion
      set /a value=0
      set /a sum=0
      FOR /R %1 %%I IN (*) DO (
      set /a value=%%~zI/1024
      set /a sum=!sum!+!value!
      )

       for /f "Delims=" %%A in (%~dp0Size.txt) do (
            set SIZE=%%A
      )

      if %SIZE%==!sum! (
      start YOUR_URL__GOES_HERE & pause
      ) else (
      Exit
      )

      If you dont wish to display the prompt during execution you could add a third file to run the batch file invisibly. This file is named "Invisible.vbs"
      don't use the (.bat) extension on this file, only use the (.vbs) extension.

      Set WshShell = CreateObject("WScript.Shell" )
      WshShell.Run chr(34) & "FileSize.bat" & Chr(34), 0
      Set WshShell = Nothing

      Place all files in the same directory.
      Your welcome :P

      « Last Edit: March 24, 2016, 06:10:52 PM by zask »