vb.net添加文件 vbnet filestream( 二 )


Dim i As Integer
'获取磁盘根目录下的文件夹
Dim str() As String = Directory.GetDirectories(DiscSymbol"\")
For i = 0 To str.GetUpperBound(0)
'调用递归过程遍历该文件夹里的所有子文件夹,并添加到树型控件
AddDirectory(DiscSymbol, str(i), Nynode)
Next
Nynode = Nothing
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
'根据磁盘符号的变更,显示根目录里的文件
ListBox1.Items.Clear()
For Each MyFile As String In System.IO.Directory.GetFiles(ComboBox1.Text)
ListBox1.Items.Add(MyFile)
Next
'根据磁盘符号的变更,重新显示目录树
Dim DiscSymbol As String
DiscSymbol = Microsoft.VisualBasic.Left(ComboBox1.Text, Len(ComboBox1.Text) - 1)
Call AddRootDirectory(DiscSymbol)
End Sub
'递归过程根据子目录寻找上级目录名--从而构成完整的目录路径
Private Sub AllPath(ByVal ThisNode As TreeNode, ByRef MyPathName As String)
If ThisNode.Level1 Then
'该节点层数大于1,其父节点不是磁盘根目录
MyPathName = ThisNode.Parent.Text"\"MyPathName
Dim MyNode As TreeNode = ThisNode.Parent
Call AllPath(MyNode, MyPathName)
Else
'该节点层数等于1,其父节点就是磁盘根目录
MyPathName = ComboBox1.TextMyPathName
End If
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
'为了搜索选中的节点对应目录的文件,需要组成全路径
Dim MyAllPathName As String = TreeView1.SelectedNode.Text
Dim MyNode As TreeNode = TreeView1.SelectedNode
If TreeView1.SelectedNode.Level = 0 Then
'如果选中的是根节点
MyAllPathName = ComboBox1.Text
Else
'如果选中的是非根节点,调用递归过程组成全路径
Call AllPath(MyNode, MyAllPathName)
MyAllPathName = MyAllPathName"\"
End If
'根据路径,搜索文件名并显示
ListBox1.Items.Clear()
For Each MyFile As String In System.IO.Directory.GetFiles(MyAllPathName)
ListBox1.Items.Add(MyFile)
Next
End Sub
End Class
VB.Net怎么创建文件举个例子:
先引入命名空间:
Imports
System.IOImports
System.Security.AccessControl
代码:
Dim
sec
As
DirectorySecurity
=
New
DirectorySecurityDim
rule
As
FileSystemAccessRule
=
New
FileSystemAccessRule("Administrator",
FileSystemRights.Delete,
AccessControlType.Allow)sec.AddAccessRule(rule)Directory.CreateDirectory("C:\test",
sec)
这段代码就是以
Administrator
帐户

C:\
创建
test
文件夹 。
vb.net怎么把一个文件夹的所有文件都添加到listbox里 。定义一个窗体继承自System.Windows.Forms.Form 。
添加以下控件对象到窗体:
Private folderBrowserDialog1 As System.Windows.Forms.FolderBrowserDialog
Private button1 As System.Windows.Forms.Button
Private listBox1 As System.Windows.Forms.ListBox
给button1的Click事件添加以下处理程序:
Sub Button1Click(sender As Object, e As EventArgs)
If System.Windows.Forms.DialogResult.OK=Me.folderBrowserDialog1.ShowDialog(Me) Then
Me.listBox1.Items.AddRange(System.IO.Directory.GetFiles(Me.folderBrowserDialog1.SelectedPath))
End If
End Sub
【vb.net添加文件 vbnet filestream】vb.net添加文件的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vbnet filestream、vb.net添加文件的信息别忘了在本站进行查找喔 。

推荐阅读