Jump to content

Prüfung ob Datei existiert und Inhalt hat


juergen_1966
 Share


Go to solution Solved by juergen_1966,

Recommended Posts

Hallo Zusammen,

ich möchte in eine Script, ähnlich wie bei dem Feiertags-Script eine Datei auslesen. Wenn diese Datei nicht existiert, sollte ein bestimmter Rückgabewert erzeugt werden.

In VBA mache ich das mit Dir(Dateiname) und prüfe dann ob der Rückgabewert <>"" ist. mache ich dies bei der Swyx, so bricht das Callrouting ab

 

Das Gleiche passiert, wenn ich zwar die Datei angelegt habe, Sie aber leer ist.

 

Der Versuch mit "on error goto xxx" habe ich ebenfalls probiert, Ergebnis genau gleich.

 

Existiert die Datei und enthält eine Zeile, dann funktioniert das call routing sauber.

 

Gibt es Einschränkungen hinsichtlich VBA bei der Swyx / Netphone? Das gleiche Script in Excel funktioniert problemlos

 

Gruss

Jürgen

Link to comment
Share on other sites


  • Most Valued User

Hallo Jürgen,

 

wenn möglich poste einmal hier dein ganzes Call Routing Script oder zumindest den VBS Code (bitte anonymisiert), dann schaue ich mal wo es hakt.
Ich werde dann den gefixten Code, dann hier bereitstellen, wenn dies für dich passt.

 

Kind regards

 

Sebastian Dreier

Link to comment
Share on other sites


Hallo Sebastian,

Danke für deine Rückmeldung.

Hier die Variante ohne on error. Wenn die Datei Picketdienst exisitiert und mindestens eine Zeile drin ist, dann klappt es 

 

' FileOpen iomode Values
Const fsoForReading   = 1
Const fsoForWriting   = 2
Const fsoForAppending = 8

 

' Picketdienst Filename
Const sFilename = "Picketdienst.txt"

 

Function GetPicketID ()

    Dim fso, file
    Dim sFile, sLine
    Dim bReturn

 

' Default Wert

bReturn = 0

 

' Create FileSystemObejct
Set fso = CreateObject("Scripting.FileSystemObject")

 

'Defintionsfile Picketdienst
sFile = "C:\T-Service\PicketDienst\" & sFilename

 

' sobald dies Zeile vorhanden ist, bricht das Script ab
strFileExists = Dir(sFile)

 

if strFileExists <> ""
  Set file = fso.OpenTextFile(sFile, fsoForReading)

  ' Lese die erste Zeile
  sLine = file.ReadLine
  ' auch hier bei einer existierenden Datei, die aber leer ist kommt es zum Abbruch

  if LCase(sLine) = "xxxx1" then bReturn = 1
  if LCase(sLine) = "xxxx2" then bReturn = 2
  if LCase(sLine) = "xxxx3" then bReturn = 3
  if LCase(sLine) = "xxxx4" then bReturn = 4

  file.Close
  Set file = Nothing

end if

 

' Aufräumen
Set fso  = Nothing

GetPicketID = bReturn
End Function
 

Link to comment
Share on other sites


  • Most Valued User

Hallo Jürgen,

 

ich habe das Script etwas angepasst und mit einer SwyxWare 13.28 getestet. Jetzt funktioniert es bei mir einwandfrei.

Manche Texte sind nun Englisch, so dass auch nicht deutschsprachige Forenbesucher etwas von diesem Code haben.
 

' Path to the file which should be read
' Important note:
' The Windows Account which is used as SwyxWare service account
' must have NTFS read rights to access this file. Otherwise a
' call routing script cannot access the file.
Const sFilePath = "C:\T-Service\PicketDienst\Picketdienst.txt"

Function GetPicketId()

    Dim fso, file
    Dim sLine
    Dim bReturn

	' Default Value
	bReturn = 0

	' Create FileSystemObejct
	Set fso = CreateObject("Scripting.FileSystemObject")

	' Ensure that file exists
	' This check will return false if the file does not exist or
	' if the server service cannot access it (NTFS rights).	
	If fso.FileExists(sFilePath) Then
	
		Set file = fso.OpenTextFile(sFilePath, 1)
	
		' Read first line
		sLine = file.ReadLine
		
		' Check line content
		Select case LCase(sLine)
		case "xxxx1"
			bReturn = 1
		case "xxxx2"
			bReturn = 2
		case "xxxx3"
			bReturn = 3
		case "xxxx4"
			bReturn = 4
		End select 
		
		' Optional tracing (is written to the IpPbxSrv.log)
		PBXScript.OutputTrace("##### GetPicketID - CallingNumber: '" & IpPbx.CallingNumber & "' / Result: " & bReturn)
		
		' Cleanup
		file.Close
		Set file = Nothing
	Else		
		' Optional tracing (is written to the IpPbxSrv.log)
		PBXScript.OutputTrace("##### GetPicketID - ERROR File does not exist or cannot be accessed: '" & sFilePath & "'")		
	End if
	
	' Cleanup
	Set fso = Nothing

	' Return result
	GetPicketId = bReturn
	
End Function 

Kind regards

 

Sebastian Dreier

 

Link to comment
Share on other sites


  • Solution

Here my final solution, thanks to the help of Sebastian

 

' FileOpen iomode Values
Const fsoForReading   = 1
Const fsoForWriting   = 2
Const fsoForAppending = 8

 

' Picketdienst Filename
Const sFile = "C:\T-Service\PicketDienst\Picketdienst.txt"

 

Function GetPicketID ()

    Dim fso, file
    Dim sLine
    Dim bReturn

 

'Default Wert
bReturn = 0

 

' Create FileSystemObejct
Set fso = CreateObject("Scripting.FileSystemObject")

 

' Ensure that file exists
' This check will return false if the file does not exist or
' if the server service cannot access it (NTFS rights).    

If fso.FileExists(sFile) Then
  Set file = fso.OpenTextFile(sFile, fsoForReading)

 

  ' make shure, that there is something to read

  if file.atEndofStream then 
    PBXScript.OutputTrace("##### GetPicketID - empy filei")
  else
    PBXScript.OutputTrace("##### GetPicketID - read file")
    ' Read first line
    sLine = file.ReadLine

    Select case LCase(sLine)
      case "XXXXX"
        bReturn = 1
      case "XXXXY"
        bReturn = 2
      case "XXXXXZ"
        bReturn = 3
      case "XXXX1"
        bReturn = 4
    End select 

    ' Optional tracing (is written to the IpPbxSrv.log)
    PBXScript.OutputTrace("##### GetPicketID - CallingNumber: '" & IpPbx.CallingNumber & "' / Result: " & bReturn)

    file.Close
    Set file = Nothing
    end if
  Else        
    ' Optional tracing (is written to the IpPbxSrv.log)
    PBXScript.OutputTrace("##### GetPicketID - ERROR File does not exist or cannot be accessed: '" & sFilePath & "'")        

 end if

 

' Aufräumen
Set fso  = Nothing

GetPicketID = bReturn
End Function
 

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.