cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 11

Scripting a file count

Jump to solution

Hello all, I'm rather knew to scripting and found this script here on thwack. I have been able to run this script from my Orion server but not through solarwinds as part of a template and am hoping you guys can point me in the right direction to remedy this. When i run this script i get this error:

ND Get Output Failed:C:\ProgramData\SolarWinds\Orion\temp\59b0ee4c-c168-4b19-bf0c-42749f2d64eb(1, 10) Microsoft VBScript compilation error: Expected end of statement.
Any thoughts? Here is the script i'm using:

' Script Name: FileCount.vbs

' Purpose: This script will return the number of files in a folder.

' Usage: cscript.exe  FileCount.vbs [pathToFiles]

' [pathToFiles] is Local or UNC Path

Option Explicit

On Error Resume Next

  Dim lstArgs, path, fso, objDir, objFiles

  Set lstArgs = WScript.Arguments

  If lstArgs.Count = 1 Then

     path       = Trim( lstArgs( 0 ))

  Else

     WScript.Echo "Message: Usage: wscript.exe filelist.vbs [pathToFiles]" &vbCRLF &"[pathToFiles] Local or UNC Path"

     WScript.Echo "Statistic: 0"

     WScript.Quit( 1 )

  End If

  Set fso  = Wscript.CreateObject( "Scripting.FileSystemObject" )

 

  If fso.FolderExists( path ) Then

    Set objDir   = fso.GetFolder( path )

    If( IsEmpty( objDir ) = True ) Then

      WScript.Echo "Message: OBJECT NOT INITIALIZED"

      WScript.Echo "Statistic: 0"

      WScript.Quit( 1 )

    End If

   

    Set objFiles = objDir.Files

    

    If( IsEmpty( objFiles ) = True ) Then

      WScript.Echo "Message: OBJECT NOT INITIALIZED"

      WScript.Echo "Statistic: 0"

      WScript.Quit( 1 )

    End If

    WScript.Echo "Message: " & CInt( objFiles.Count ) & " FILES"

    WScript.Echo "Statistic: " & CInt( objFiles.Count )

    WScript.Quit( 0 )

   

  Else

    WScript.Echo( "Message: FOLDER NOT FOUND" )

    WScript.Echo "Statistic: 0"

    WScript.Quit( 1 )

  End If

0 Kudos
1 Solution
Level 11

for a unc with spaces  you need 3 quotation marks. Thank you to solarwinds support for helping me solve this problem.

View solution in original post

0 Kudos
2 Replies
Level 11

for a unc with spaces  you need 3 quotation marks. Thank you to solarwinds support for helping me solve this problem.

View solution in original post

0 Kudos

can you please help me where i need to provide the 3 quotation marks i am also using the same script to monitor the folder.

0 Kudos