vbscript如何检查txt文件是否存在以及何时不创建空文件 [英] vbscript how to check if txt file exists and whe not create empty one

查看:16
本文介绍了vbscript如何检查txt文件是否存在以及何时不创建空文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 vbscript 检查 C:\Temp\CAD_Kunde.txt 中的 txt 文件是否存在,不存在时应为空创建.

How can i check with vbscript if the txt file in C:\Temp\CAD_Kunde.txt exists and when it does not exist it should be empty created.

我收到一个错误(当我使用这个时,第 11 行第 1 行的预期语句:

I get an error (Expected Statement on Line 11 Char 1 when i use this:

   <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>

推荐答案

<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>

这篇关于vbscript如何检查txt文件是否存在以及何时不创建空文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆