Computing.Net > Forums > Programming > Batch file for checking filesize

Batch file for checking filesize

Reply to Message Icon

Original Message
Name: Mekkel
Date: June 8, 2007 at 04:19:32 Pacific
Subject: Batch file for checking filesize
OS: XP
CPU/Ram: p4 3.0GHz 512mb
Model/Manufacturer: Fujitsu
Comment:

Hi, I'm currently struggling with a problem. I want to create a batch file that checks the file size of a file, and compares the size with the last time it was checked. If it's equal it has to do nothing, but if it's changed I would like to receive an e-mail. I'm pretty new at this stuff so I appreciate any help.

Thanks in advance



Report Offensive Message For Removal

Response Number 1
Name: Mechanix2Go
Date: June 8, 2007 at 06:44:25 Pacific
Subject: Batch file for checking filesize
Reply: (edit)

::== cheksize.bat
@echo off
setLocal EnableDelayedExpansion

for %%a in (myfile) do (
set now=%%~za
)
if not exist %temp%\# echo !now!>%temp%\# && echo no prev && goto :eof
set /p prev=<%temp%\#
if !now! equ !prev! echo still same size && goto :eof

echo here's where you send the email
echo !now!>%temp%\#
::==



=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 2
Name: ghostdog
Date: June 8, 2007 at 08:35:12 Pacific
Subject: Batch file for checking filesize
Reply: (edit)

here's a vbscript.
[code]
sFileName="C:\temp\monitor.txt"
cFileName="C:\temp\test.bat"
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(sFileName) Then
Set oTS = FSO.OpenTextFile(sFileName)
OldFileSize = oTS.ReadAll
oTS.Close
Set efile = FSO.GetFile(cFileName)
newFileSize = efile.Size
If CInt(newFileSize) <> CInt(OldFileSize) Then
WScript.Echo "email here"
WScript.Quit(1)
Else
WScript.Echo "same size"
WScript.Quit(0)
End If
Else
Set oTS = FSO.CreateTextFile(sFileName)
Set efile = FSO.GetFile(cFileName)
newFileSize = efile.Size
oTS.WriteLine(newFileSize)
oTS.Close
End If

[/code]

batch :
[code]
cscript myscript.vbs
if %errorlevel% equ 1 send email...
[/code]


Report Offensive Follow Up For Removal

Response Number 3
Name: Mekkel
Date: June 11, 2007 at 02:21:14 Pacific
Subject: Batch file for checking filesize
Reply: (edit)

This did the trick, thanks a lot!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch file for checking filesize

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software