Begin Const
$CMD = App.Environ.Comspec & " /c "
$notPermitted = Chr$(0 to 31, 34,42,47,59,60,62,63,92,124,126,127)
$needsQuotes = chr$(32 to 45,58 to 64, 91 to 94, o6, 123 to 127)
End Const
' direct access the cmd.exe-command-
' interpreter from thinbasic:
Function Exist(Byval sPath as String) As Boolean
Boolean bNetPath
' if a folders existence is to test
' the path must end with a backslash
' you may concetanate strings for the
' sPath-parameter without to care about quotes
' or if a backslash was present already, just put
' one inbetween, duplications are removed
sPath = Remove$(sPath, $Dq)
sPath = REPLACE$(sPath, "/" With "\")
bNetPath =Startswith(sPath,"\\")
If bNetpath Then sPath = RightF$( sPath, -2)
' if there is an error because of -2 upon RightF$
' use RightF$(sPath, LenF(sPath) - 2)
While instr(1, sPath, "\\")
sPath =REPLACE$(sPath,"\\", With "\")
Wend
If bNetPath then sPath ="\\" & sPath
If instr(1, sPath, any $needsQuotes) then sPath = $Dq & sPath & $Dq
FUNCTION =("TRUE" = Shell_CaptureOutput( $CMD & " Exist " & sPath & " (ECHO TRUE) ELSE (ECHO FALSE)", "", %SW_Hide, 10))
End Function
Sub Write_File(Byval sPath as String, Byval sText As String, Opt Byval bAppend As Boolean
String sq, sa
If Instr(1,sPath, Any $NotPermitted) Then
MsgBox "Error:" & $Crlf &"Path-Parameter contains invalid char." & $Crlf & $dq & sPath & $Dq, %MB_iconError, Function_name
Exit Sub
End If
If Instr(1, sPath, Any $needsQuotes) then sq =$DQ
sa = iif$( bAppend, ">>", ">")
If Shell_CaptureOutput( StrFormat$("{1} (Echo {2})>{3}{4}{5}{4}", $Cmd, sText, sa, sq, sPath), "", %SW_Hide, 10) then Nop
End Sub
It may be difficult to pass more than a few verbs because ^ (circonflex) is the escape-char that needs to be added before newline in order to escspe from end of line and to continue on the following line. We would just put the string in quotes - that won't work here.
Bookmarks