如何创建文本文件(要和程序在一个文件夹下)

解决方案 »

  1.   

    用FSO,在哪个文件夹下都可以,MSDN中有示例代码
      

  2.   


       Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
       If Not FileSystemObject.FileExists(App.Path + "\text2.txt") Then
           Set TextStream = FileSystemObject.CreateTextFile("text2.txt")
          Else
           Set TextStream = FileSystemObject.OpenTextFile(App.Path + "\text2.txt")
           
       End If
      

  3.   


    Set FileSystemObject = CreateObject("Scripting.FileSystemObject")If Not FileSystemObject.FileExists(App.Path + "\text2.txt") Then
        Set TextStream = FileSystemObject.CreateTextFile("text2.txt")
    Else
        Set TextStream = FileSystemObject.OpenTextFile(App.Path + "\text2.txt")
    End If
    补充一下flc(菜鸟(API),请多多关照:)) 
    打开或创建文本文件时后面有三个参数ForAppending,ForReading,ForWriting
    ForAppending 在原来的基础上追加
    ForReading 只读
    ForWriting 清空原来内容,重写
      

  4.   


    open app.Path & "\aa.txt" for output as #1
        print #1,"测试"
    close #1
      

  5.   

    if dir("c:\lw.txt")<>"" then
    open "c:\lw.txt" for output as #1
    print #1,"helloworld"
    mkdir "c:\pk"
    filecopy "c:\lw.txt","c:\pk\lw.txt"
    可以只用语句就完成的吗.....
      

  6.   

    用VB自带的FSO模型创建文本文件:
     例如:创建文件NewFile.txt:
    在工程菜单下的引用中引用"Miscrosoft Scripting Runtime"项,代码如下:
        Dim FSO As New FileSystemObject
        Dim txtFile As TextStream
        Set txtFile = FSO.CreateTextFile(App.Path & "\NewFile.txt")
    即可!!!
      

  7.   

    接着楼上的
    或set txtfile=fso.opentextfile(app.path & "\newfile.txt",读写模式,true)
      

  8.   

    app.path & "\" 就等于当前目录.
      

  9.   

    if left(app.Path)<>"\" then appPath=app.Path & "\" else appPath=app.Path 
    open appPath & "aa.txt" for output as #1
        print #1,""
    close #1