我如何使用 vbscript 检查 C:\Temp\CAD_Kunde.txt 中的 txt 文件是否存在,如果不存在,则应将其创建为空。
编辑:我收到错误(当我使用此命令时,第 11 行字符 1 上的预期语句:
<SCRIPT Language="VBScript">
Sub Window_OnLoad
//Line 11 is the one below:
Option Explicit
Dim oFSO, oTxtFile
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists("C:\Temp\CAD_Kunde.txt") then
Msgbox "File Exist"
Else
Set oTxtFile = oFSO.CreateTextFile("C:\Temp\CAD_Kunde.txt")
Msgbox "File Created"
End If
End Sub
</script>
Run Code Online (Sandbox Code Playgroud)
小智 5
<SCRIPT Language="VBScript">
Sub Window_OnLoad
Option Explicit
Dim oTxtFile
With (CreateObject("Scripting.FileSystemObject"))
If .FileExists("C:\Temp\CAD_Kunde.txt") Then
Msgbox "File Exist"
Else
Set oTxtFile = .CreateTextFile("C:\Temp\CAD_Kunde.txt")
Msgbox "File Created"
End If
End With
End Sub
</script>
Run Code Online (Sandbox Code Playgroud)