十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
创新互联是一家专业提供喀左企业网站建设,专注与成都网站制作、成都网站设计、成都h5网站建设、小程序制作等业务。10年已为喀左众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。
Dim a As String = "c:\windows\system"
For Each ws In My.Computer.FileSystem.GetFiles(a)
Dim kzm As String = ws.Substring(InStrRev(ws, "."), ws.Length - InStrRev(ws, ".")) '定义扩展名变量
If kzm = "mp4" Or kzm = "avi" Or kzm = "flv" Then '这里一定要注意扩展名的大小写,如aviAVI的
Me.ListBox1.Items.Add(ws)
End If
Next
End Sub
vb.net编程查找搜索指定目录下面的所有文件和其子目录下的文件,方法如下:
''=============================================
''名称: FindPath
''作用: 查找搜索指定目录下面的所有文件和其子目录下的文件
''参数:strPath 要查找的目录,
''strFiles 用于存查找结果的缓冲区,String 类型的动态数组,调用时事先初始化, 如Redim strFiles(0)
''FileCount 用于返回文件个数
''=============================================
Public Sub FindPath(ByVal strPath As String, strFiles() As String, FileCount As Long)
Dim strDirs() As String
Dim strResult As String
Dim FileLimit As Long
Dim dirLimit As Long
Dim dirCount As Long
Dim I As Long
FileLimit = UBound(strFiles) + 1
dirLimit = 0
If Right$(strPath, 1) "/" Then strPath = strPath "/"
strResult = Dir(strPath, vbDirectory + vbSystem + vbReadOnly + vbHidden + vbNormal + vbArchive)
Do While Len(strResult) 0
If strResult "." And strResult ".." Then
If (GetAttr(strPath strResult) And vbDirectory) vbDirectory Then
If FileCount = FileLimit Then
ReDim Preserve strFiles(FileLimit + 10)
FileLimit = FileLimit + 10
End If
strFiles(FileCount) = strPath strResult
FileCount = FileCount + 1
Else
If dirCount = dirLimit Then
ReDim Preserve strDirs(dirLimit + 10)
dirLimit = dirLimit + 10
End If
strDirs(dirCount) = strPath strResult
dirCount = dirCount + 1
End If
End If
strResult = Dir(, vbDirectory + vbSystem + vbReadOnly + vbHidden + vbNormal + vbArchive)
Loop
For I = 0 To dirCount - 1
Call FindPath(strDirs(I), strFiles, FileCount)
Next I
End Sub
Server.MapPath("~") "\" "Web.config"Server.MapPath("~") 是取当前目录上一级的路径Server.MapPath(".") 是取当前目录的路径
先用System.IO.Directory.GetDirectories函数获取子目录的名称(包括其路径),再用System.IO.Path.GetFileName获取子目录的名称。下面是代码:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
For Each s In System.IO.Directory.GetDirectories("C:\Windows")
Console.WriteLine(System.IO.Path.GetFileName(s))
Next
End Sub
下面是部分输出:
Application Data
AppPatch
assembly
BOCNET
Boot
Branding
ConfigSetRoot
Cursors
Debug
DigitalLocker
Downloaded Installations
Downloaded Program Files
ehome
en-US
Fonts
Globalization
Help
...
可能有更简洁的方法,你可以到MSDN看看
System.IO.Directory.GetDirectories:
System.IO.Path.GetFileName:
通用 I/O 任务: