VBScript fopen function

A VBScript equivalent of PHP’s fopen

Public function fopen(filename, mode)

    Dim filePath
    filePath = fileMapPath(filename)

    If left(filePath,len("http://")) = "http://" Then
        fopen = file_get_contents(filePath)
        Exit Function
    End If

    Select Case mode
    Case "r"
        Set ts = fso.OpenTextFile(filePath,1,false)
    Case "w"
        Set ts = fso.OpenTextFile(filePath,2,true)
    Case "a"
        Set ts = fso.OpenTextFile(filePath,8,true)
    Case "x"
        If is_file(filePath) Then
            fopen = false
            Set ts = fso.OpenTextFile(filePath,2,true)
        End If
    Case Else
        ts = false
    End Select

end function

Please also note that php.vbs offers community built functions and goes by the McDonald’s Theory. We’ll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just:

Other PHP functions in the filesystem extension