GetLogicalDrives 检索此计算机上格式为“<盘符>:\”的逻辑驱动器的名称。
GetParent 检索指定路径的父目录,包括绝对路径和相对路径。
![]() ![]() | Delete(String, Boolean) |
Delete(String) |
![]() | Move |
![]() | Move |
![]() | Move |
下面给以段自己编写的文件夹和文件的创建删除
Imports System.IO
Public Class WebForm1
Inherits System.Web.UI.Page
Private Property path As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim iDir As IO.Directory
Dim node As New TreeNode
'先把C盘添加到树中
TreeView1.Nodes.Clear()
' node.ImageIndex = 0
node.Text = "本地磁盘 D:"
' node.SelectedImageIndex = -1
TreeView1.Nodes.Add(node)
Dim i As Integer
'获取d:盘根目录下的文件夹
Dim str() As String = Directory.GetDirectories("d:\")
For i = 0 To str.GetUpperBound(0)
'调用遍历过程
AddDirectory("D:", str(i), node)
Next
node = Nothing
iDir = Nothing
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Me.获取创建路径()
Dim sw As System.IO.StreamWriter = System.IO.File.CreateText(path)
sw.Write(Me.TextBox1.Text.ToString())
sw.Close()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
Me.获取删除路径()
Me.TextBox1.Text = path
System.IO.File.Delete(path)
End Sub
Sub 获取创建路径()
path = Me.TextBox2.Text.ToString.Trim
Me.创建路径(path, True)
path = Me.TextBox2.Text & Me.TextBox3.Text
End Sub
Sub 创建路径(ByVal 路径 As String, ByVal 是否覆盖 As Boolean)
Dim saveFullPath As String = String.Empty
If (是否覆盖) Then
'saveFullPath = System.Web.HttpContext.Current.Server.MapPath(路径)
' Else
saveFullPath = 路径
End If
If (Not Directory.Exists(saveFullPath)) Then
Try
Directory.CreateDirectory(saveFullPath)
Catch ex As Exception
End Try
End If
End Sub
Sub 获取删除路径()
' Dim flodpath As String = Server.MapPath("~")
'path = flodpath & Me.FileUpload1.PostedFile.FileName.Replace("\", "/")
path = Me.FileUpload1.PostedFile.FileName.Replace("\", "/")
End Sub
'添加文件夹
Public Sub AddDirectory(ByVal strFatherPath As String, ByVal strPath As String, ByVal nodeFather As TreeNode)
Dim iDir As IO.Directory
' Dim iDirInfo As IO.DirectoryInfo
Dim i As Integer
Dim node As New TreeNode
'先添加本目录,从文件夹路径分析出文件夹名称
node.Text = Strings.Replace(strPath, strFatherPath & "\", "", , 1)
'为单个节点指定节点未被选中时显示的图标
' node.Image()
' node.ImageIndex = 1
'为单个节点指定节点被选中时显示的图标
' node.SelectedImageIndex = 2
nodeFather.ChildNodes.Add(node)
' Application.DoEvents()
Try
Dim str() As String = Directory.GetDirectories(strPath)
'遍历该目录的子文件夹
For i = 0 To str.GetUpperBound(0)
AddDirectory(strPath, str(i), node)
Next
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
node = Nothing
iDir = Nothing
End Sub
End Class
Delete(String) |
给个工程源代码下载,要是有朋友下下来修改后麻烦发我邮件一份,一起学习,谢谢