导航:首页 > 文件教程 > vb怎么得到子文件夹

vb怎么得到子文件夹

发布时间:2023-03-16 04:29:20

Ⅰ vb 如何读取某目录下所有文件及子文件夹

查找某目录下所有 文件 及 子文件夹
试一试不用 FileSystemObject 对象,只用基本控件的代码
'例子需控件:Command1,List1,List2,File1,Dir1,都采用默认属性。
'例如,查找 C:\ ,带 '** 的语可修改

Dim ctFind As Boolean
Private Sub Form_Load()
Me.Caption = "查找所有文件及文件夹"
Command1.Caption = "查找"
List2.Visible = False: File1.Visible = False: Dir1.Visible = False
Label1.Caption = "就绪"
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
Private Sub Form_Resize()
Dim W As Long
On Error Resume Next
W = 720
List1.Move 0, 0, Me.ScaleWidth - W - 120, Me.ScaleHeight - 300
Command1.Move Me.ScaleWidth - W - 60, 300, W
Label1.Move 90, Me.ScaleHeight - 255, Screen.Width, 255
End Sub
Private Sub Command1_Click()
ctFind = Not ctFind
If ctFind Then
Command1.Caption = "取消"
Call FindDirFile("C:") '**查找 C:\ 下的所有文件和目录,或 C:\Windows 等
Command1.Caption = "查找"
Else
Command1.Caption = "查找"
End If
End Sub
Private Sub FindDirFile(ByVal nPath As String)
Dim I As Long, nDir As String, Ci As Long
ctFind = True
List1.Clear: List2.Clear
If Right(nPath, 1) <> "\" Then nPath = nPath & "\"
List1.AddItem "查找 " & nPath: List2.AddItem nPath
File1.Pattern = "*"
File1.System = True: File1.Hidden = True: File1.ReadOnly = True
On Error GoTo Cuo
Dir1.Path = nPath
On Error GoTo 0
Do
If List2.ListCount = 0 Then Exit Do
nPath = List2.List(0)
List2.RemoveItem 0
Dir1.Path = nPath
For I = 0 To Dir1.ListCount - 1
GoSub ShowGe
nDir = Dir1.List(I)
If Right(nDir, 1) <> "\" Then nDir = nDir & "\"
List1.AddItem "■" & nDir
List2.AddItem nDir
Next
File1.Path = nPath
For I = 0 To File1.ListCount - 1
GoSub ShowGe
List1.AddItem " " & nPath & File1.List(I)
Next
Loop
Label1.Caption = "查找完毕,共找到 " & List1.ListCount & " 个条目"
ctFind = False
Exit Sub
Cuo:
List1.AddItem "起始目录不存在:" & nPath
ctFind = False
Exit Sub
ShowGe:
Ci = Ci + 1
If Ci < 99 Then Return
Ci = 0
Label1.Caption = "已找到 " & List1.ListCount & " 个:" & nPath
DoEvents
If ctFind Then Return
End Sub

Ⅱ vb2013 如何获取指定目录下及子目录下所有文件

这个分两个步骤。

第一步是利用 System.IO.DirectoryInfo 类的 GetDirectories() 方法,遍历指定目录下慎卜的所有子目录。裤仿

第二步是利用 System.IO.DirectoryInfo 类的 GetFiles() 方法,遍历这些子目录(包括根目录)下的所有文件。

原理就是这样,代码可参考:宽纯穗http://blog.csdn.net/aspnet2002web/article/details/6087476 这篇博文。

Ⅲ vb 获得一个文件夹下所有子文件夹名,并全部添加到组合框里,只要文件名,不要全部路径

添加一个Dirlistbox,Textbox,一个按钮,一个组合框...
按钮的简谈单击拦弯碰事件如下

Private Sub Command1_Click()
Dim i As Integer
Dim b As Integer
Dim a As String
a = Text1.Text
Dir1.Path = a
b = Len(a)
Combo1.Clear
For i = 0 To Dir1.ListCount - 1
Combo1.AddItem (Mid(Dir1.List(i), b + 1))
Next
End Sub

运行时候,在闹返TextBox里输入文件路径,如 C:\windows\ 这里路径后面把"\"要加上,然后,单击按钮,再查看组合框,就可以看到windows目录下了。。。
以上程序在我的机子(XP,SP2版,VB6.0企业版)上测试通过

Ⅳ vb treeview 显示指定文件夹、子文件夹及文件名 逐级显示出来 请高手指教

vb.net。
通过指定文件夹的路径,获取子文件夹My.Computer.FileSystem.GetDirectories
通过指定文件夹的路径,获取文件名My.Computer.FileSystem.GetFiles。
将不包括路径的文件名和文件夹名增加到treeview中。
TreeView1.Nodes.Add增加一级节点
TreeView1.Nodes(0).Nodes.Add增加第一个一级节点的子节点
TreeView1.SelectedNode.Nodes.Add(“”)增加当历唤前选定节点的子节点
TreeView1.SelectedNode.FullPath返肢运凯回当前选定节点的路径。
要代码可追问,问题再详细具悄脊体些吧。你是要做资源管理器类型的?文件夹和文件都显示在treeview中?

Ⅳ 如何用VB获得某一目录下的所有文件和文件夹名称

Dim a() As String
Private Sub Dir1_Change()
File1.Path = Dir1.Path
Label1.Caption = Dir1.Path
End Sub
Private Sub Drive1_Change()
On Error GoTo err1
Dir1.Path = Drive1.Drive
Exit Sub
err1:
MsgBox Err.Description, vbInformation + vbOKOnly, "提示"
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim ifieldcount As Integer, irecordcount As Integer
Dim wdapp As Word.Application
Dim wddoc As Word.Document
Dim atable As Word.Table
If Option2.Value = True Then
ReDim a(1 To File1.ListCount)
For i = 1 To File1.ListCount
b = File1.List(i)
a(i) = b
Next
End If
If Option1.Value = True Then
ReDim a(1 To Dir1.ListCount)
For i = 1 To Dir1.ListCount
b = Dir1.List(i)
a(i) = b
Next
End If
End Sub

这段程序 复制过去 就行了 创建的控件有 两个option 让你选择 要提取文件夹 还是文件路径的 选中option 1 就是提取文件夹的 option2 就是提取文件的 然后再创建 Drive1 Dir1 File1 这三个 选择文件路径的 控件 再加一个 command 按钮 就行了 有疑问再联系我!!!!!这个 只是 文件路径 你看看 是你想要的话 我再给你写 提取文件夹和文件名的代码!!!!

Ⅵ 如何用VB自动生成Folder文件夹并在文件夹内添加固定模式的子文件夹

先在工局坦程里面引用microsoft scripting runtime,然桐基桐后锋毁编写代码

Dim fso As New FileSystemObject

Private Sub Command1_Click()
Dim s$, i%
s = "c:"
For i = 1 To 5
fso.CreateFolder s + "\folder " + CStr(i)
s = s + "\folder " + CStr(i)
Next
End Sub

Ⅶ 谢谢,又来个问题,vb6中怎么得到一个文件夹下面的所有文件夹的名称

'fvFolderPath表枯睁判示所给早码文件夹
Public Sub GetSubDirs(ByRef fvFolderPath As String)
Dim oFso As New FileSystemObject
Dim oParentFolder As Folder
Dim oFolders As Folders
Dim oFolder As Folder
Dim vFolderName As String
Dim oCollection As New VBA.Collection

Set oParentFolder = oFso.GetFolder(fvFolderPath)
‘得到所给文件夹的子文件夹集合
Set oFolders = oParentFolder.SubFolders
’循环,得到每个没改子文件夹名称,并写入ocollection集合中
For Each oFolder In oFolders
vFolderName = oFolder.Name
Call oCollection.Add(vFolderName)
Debug.Print vFolderName
Next

End Sub

阅读全文

与vb怎么得到子文件夹相关的资料

热点内容
maya粒子表达式教程 浏览:84
抖音小视频如何挂app 浏览:283
cad怎么设置替补文件 浏览:790
win10启动文件是空的 浏览:397
jk网站有哪些 浏览:134
学编程和3d哪个更好 浏览:932
win10移动硬盘文件无法打开 浏览:385
文件名是乱码还删不掉 浏览:643
苹果键盘怎么打开任务管理器 浏览:437
手机桌面文件名字大全 浏览:334
tplink默认无线密码是多少 浏览:33
ipaddgm文件 浏览:99
lua语言编程用哪个平台 浏览:272
政采云如何导出pdf投标文件 浏览:529
php获取postjson数据 浏览:551
javatimetask 浏览:16
编程的话要什么证件 浏览:94
钱脉通微信多开 浏览:878
中学生学编程哪个培训机构好 浏览:852
荣耀路由TV设置文件共享错误 浏览:525

友情链接