我如何用vbscript检查C:\Temp\CAD_Kunde.txt中的txt文件是否存在,如果它不存在,应该是空创建的。
编辑:我得到一个错误(当我使用下面的代码时,第11行Char 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>发布于 2012-02-27 21:38:20
<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>发布于 2012-02-27 21:15:52
这很简单
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发布于 2012-02-28 00:04:48
如果您不关心区分exist/not exists,只想确保存在一个,那么您可以
set f = CreateObject("Scripting.FileSystemObject").OpenTextFile("c:\blabla", 1, true)
f.close()https://stackoverflow.com/questions/9465278
复制相似问题