Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to check for files in share?

Status
Not open for further replies.

bowwow

IS-IT--Management
Jun 11, 2002
60
GB
Hi All

Im new to vb scripting. Does anyone know how to get a vb script to check for files in a network share? (not a folder). I will alert when there 'x' files and raise a critical alrte when there are 'y' files. The network share is also on a cluster if that makes any difference? The script will run on the active node of the cluster.

Any help much appreciated.
Kind Regards
Andy
 
There is no difference between a folder and a share in this case. You will simply substitute a UNC for a local path.

This is really easy if you don't have to worry about sub folders.

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set oFolder = objFSO.GetFolder("\\127.0.0.1\C$\Windows")

intFileCount = oFolder.Files.Count

wscript.echo intFileCount

If you need to consider sub folders then it is probably more practical to be looking at the folder size rather than the number of files within it.

Code:
On Error Resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = objFSO.GetFolder("\\127.0.0.1\C$\LabSoftware")

If oFolder.Size < 102400 Then
    wscript.echo oFolder.Size/1024\1024 & "MB"
Else
    wscript.echo oFolder.Size/1024/1024\1024 & "GB"
End If

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top