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添加文件的信息别忘了在本站进行查找喔 。
推荐阅读
- plsql执行oracle存储过程,oracle中plsql执行语句
- ios升级消除游戏叫什么,iphone升级取消
- 公众号注册身份信息,注册微信公众号身份证姓名
- 钉钉能用单反直播,钉钉直播可以用摄像机吗
- go语言直接编译成原生码 go怎么从源码编译到二进制文件
- u盘装系统有什么好处,u盘装系统教程图解win10
- html5开发报价,h5页面开发价格
- 四川专业sap软件维护,sap维护是什么意思
- vb.net播放资源音乐 vb音乐播放器代码