如果文件存在就读取,没有则创建个

解决方案 »

  1.   

    dim fso as filesystemobject
    set fso=new filesystemobjectif fso.fileexists(Filename) then
     'open
    else
     'Create
    endifset fso=nothing
      

  2.   

    If Dir("c:\txt1.txt") = "" Then'文件不存在
         Open "c:\txt1.txt" For Output As 1
         '写文件
         ……
    Else
        Open "c:\txt1.txt" For Input As 1
        '读文件
         ……
    End if
    Close 1
      

  3.   

    用这个API:PathFileExists,因为我现在在网吧,所以不能给你具体的声明,自已到APIVIEWER一查就知道了。
      

  4.   

    Function findfile(dirpath As String, filename As String) As Boolean
    findfile = True
    dirpath = IIf(Right(dirpath, 1) = "\", dirpath, dirpath & "\")
    If Dir(dirpath & filename) = "" Then findfile = False
    End Function