zoukankan      html  css  js  c++  java
  • 【VB】VB文件系统操作


    针对txt,Word,Execl都可以使用
    顺序文件:
    (1)创建:
        Open "D:\test.doc" For Output As #1 //创建
        Output 写入
        Append写入
        Input 读取
     (2)写入
            Print #1, "ASDFREWFGH"  //写入
            Write #1,"aaaaaaaaaa"  //写入
    (3)读取
       Input #2, inputdate
       Text1.Text = inputdate
       Line Input #2,inputdate
       Input(Number,#1)
    (4)关闭
        Close


    随机文件:
    (1)创建:
        Open "D:\test.doc" For Random  Access  Read As #1 Len=100 //创建
     (2)写入
            Put #1, 2,Rec  //写入
            用变量Rec来替代位置为2的记录  
    (3)读取
       Get #2,2, Rec
       将一个记录从#2 文件中复制到变量Rec中,2是要读取的记录号
    (4)关闭
        Close

    二进制文件
    (1)创建:
        Open "D:\test.doc" For Binary As #1 //创建
     (2)写入
            Put #1, 2,Rec  //写入
            用变量Rec来替代位置为2的记录  
    (3)读取
       Get #2,2, Rec
       将一个记录从#2 文件中复制到变量Rec中,2是要读取的记录号
    (4)关闭
        Close

    VB文件系统控件
    1.驱动器列表框(DriveListBox)  Drive1
    2.目录列表框(DirListBox)  Dir1
    3.文件列表框(FileListBox) File1

    设置对应关系过程:
    Private Sub Drive1_Change()
       Dir1.Path = Drive1.Drive
    End Sub

    Private Sub Dir1_Change()
       File1.Path = Dir1.Path
    End Sub

    VB  FSO对象模型
    应用 "Microsoft Scripting Runtime"
    Drive对象,Folder对象,File对象,TextStream对象
     创建FSO对象:
      (1)Dim MyFSO As New FileSystemObject
      (2)Set MyFSO = CreateObject("Scripting.FileSystemObject")

    Dim MyFSO As New FileSystemObject
    Dim MyFolder As Folder
    Dim MyFile As File
    Set MyFolder = MyFSO.CreateFolder("D:\Test") //创建文件夹
    Print "Create:"; MyFolder.Name

    Set MyFile = MyFSO.CreateTextFile("D:\Test1.txt", True)//创建文件


     
     



  • 相关阅读:
    Spring学习笔记之四----基于Annotation的Spring AOP编程
    Spring学习笔记之三----基于Annotation的Spring IOC配置
    Spring学习笔记之一----基于XML的Spring IOC配置
    Spring学习笔记之二----基于XML的Spring AOP配置
    Swift语言之类型方法
    Swift语言之命令模式(Command Pattern)实现
    用Swift语言做App开发之单元测试
    Spring Batch学习笔记三:JobRepository
    Spring Batch学习笔记二
    初探Spring Batch
  • 原文地址:https://www.cnblogs.com/cuishao1985/p/1530998.html
Copyright © 2011-2022 走看看