VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > 批处理教程 >
  • vb.net教程之有关文件、文件夹操作的控件

有关文件、文件夹操作的控件 (相关vb.net教程)
文件操作是通过文件系统对象file directory来完成的,它可以完成文件(夹)的如下操作:创建、删除、复制、更名等。
复习通用对话框控件OpenFileDialog1及方法、属性:ShowDialog、FileName
(一)、File对象
命名空间:System.IO.File
作用:完成文件的创建、复制、移动、删除、打开等操作
常用方法:
Copy—复制文件
Create—创建新文件
Delete—删除文件
Move—移动文件
Open—打开文件,如果文件不存在,有创建功能。
Openread—打开文件并读出。
Openwrite—打开文件并写入。
应用实例:以文件的创建、复制、移动、删除为例来说一下文件操作的应用。[实验报告43]
程序见,file对象与文件操作
程序清单为:
Public Class Form1
    Dim f As System.IO.File
    Dim sourcename, desname As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.ShowDialog()
        sourcename = OpenFileDialog1.FileName
        TextBox1.Text = sourcename
        desname = InputBox("请输入目标文件名", "目标文件")
        f.Copy(sourcename, desname, True)
        TextBox2.Text = desname
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        OpenFileDialog1.ShowDialog()
        sourcename = OpenFileDialog1.FileName
        TextBox1.Text = sourcename
        f.Delete(sourcename)
    End Sub
 
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        OpenFileDialog1.ShowDialog()
        sourcename = OpenFileDialog1.FileName
        TextBox1.Text = sourcename
        desname = InputBox("请输入要移动的目标文件名", "移动文件")
        f.Move(sourcename, desname)
        TextBox2.Text = desname
    End Sub
 
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        desname = InputBox("请输入要新建的目标文件名", "新建文件")
        TextBox1.Text = desname
        f.Create(desname)
    End Sub
 
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        desname = InputBox("请输入要打开的目标文件名", "打开文件")
        TextBox1.Text = desname
        f.Open(desname, IO.FileMode.Create, IO.FileAccess.Write)
End Sub
 
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        End
    End Sub
 
End Class

相关教程