如我想在WINDOWS目录下建立一个文件,而不管文件里面有没有内容。
还有如何判断一个文件是否存在。

解决方案 »

  1.   

    查找ini文件
    If Dir(App.Path & "\dbcredit.ini") = "" Then
    msgbox ""
    end if
    新建ini文件
    Open App.Path & "\dbcredit.ini" For Output As #1
     Print #1, "This is a test" ' 将文本数据写入文件
    打开文件
    Open App.Path & "\mscredit.ini" For Input As #1
    Input #1, ms
    Close #1
    看看对你有没有帮助
      

  2.   

    把TextBox内容写入文本文件:
    Dim TempFile As Long
    Dim SaveBytes() As ByteSaveBytes=StrConv(Text1.Text,vbFromUniCode)TempFile=FreeFile
    Open 文件名 For Binary As #TempFile
    Put #TempFile,,SaveBytes
    Close TempFile
      

  3.   

    '*********************************************************
    '* 名称:FileExists%(filename$)
    '* 功能:此函数用于判断文件是否存在
    '* 用法:FileExists%('文件名称')
    '* 文件不存在返回 0
    '*********************************************************
    Function FileExists%(filename$)
        Dim F%
        
        On Error Resume Next
        
        F% = FreeFile
        Open filename$ For Input As #F%
        Close #F%
        
        FileExists% = Not (Err <> 0)
    End Function
      

  4.   

    If Dir("c:\aaa.txt") = "" Then
       msgbox "存在
    else
       msgbox "不存在"
    endif
      

  5.   

    这个API也可建立文件Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long