Computer Hope

Microsoft => Microsoft DOS => Topic started by: masterwix on March 02, 2016, 02:36:03 AM

Title: batch script to monitor folder size
Post by: masterwix 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!
Title: Re: batch script to monitor folder size
Post by: zask 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