vb文件夹列表
① VB怎么获得FTP服务器的文件以及文件夹列表
public strData as string
'这段可以返回服务器中的第一级目录名,保存在strData中, 如有多个文件夹名每个文件夹名会以空格分开。读取时判段一下。
Inet1.Execute Inet1.URL, "dir """ & dirName & """"
Do
DoEvents
Loop While Inet1.StillExecuting = True
msgbox strData
'这段是进入目录中,要想获得服务器中所有的文件夹名,就可以用递规的办法来获得。
Inet1.Execute Inet1.URL, "cd """ & dirName & """"
Do
DoEvents
Loop While Inet1.StillExecuting = True
Private Sub Inet1_StateChanged(ByVal State As Integer)
Select Case State
Case 1
StatusBar1.Panels.Item(1).Text = "该控件正在查询所指定的主机的 IP 地址"
Case 2
StatusBar1.Panels.Item(1).Text = "该控件已成功地找到所指定的主机的 IP 地址"
Case 3
StatusBar1.Panels.Item(1).Text = "该控件正在与主机连接"
Case 4
StatusBar1.Panels.Item(1).Text = "该控件已与主机连接成功"
Case 5
StatusBar1.Panels.Item(1).Text = "该控件正在向主机发送请求"
Case 6
StatusBar1.Panels.Item(1).Text = "该控件发送请求已成功"
Case 7
StatusBar1.Panels.Item(1).Text = "该控件正在接收主机的响应"
Case 8
StatusBar1.Panels.Item(1).Text = "该控件已成功地接收到主机的响应"
Case 9
StatusBar1.Panels.Item(1).Text = "该控件正在解除与主机的连接"
Case 10
StatusBar1.Panels.Item(1).Text = "该控件已成功地与主机解除了连接"
Case 11
MsgBox "与主机通讯时出现了错误", vbInformation, "个人资料"
Case 12
Dim vtData As Variant
Dim bDone As Boolean
bDone = False
'取得第一个块。
vtData = Inet1.GetChunk(1024, icString)
DoEvents
Do While Not bDone
strData = strData & vtData
'取得下一个块。
vtData = Inet1.GetChunk(1024, icString)
DoEvents
If Len(vtData) = 0 Then
bDone = True
End If
Loop
StatusBar1.Panels.Item(1).Text = "该请求已经完成,并且所有数据均已接收到"
Case Else
StatusBar1.Panels.Item(1).Text = Inet1.ResponseCode & ": " & Inet1.ResponseInfo
End Select
End Sub
② vb查看文件夹中有哪些文件
Sub 获取指定文件夹的文件列表()
Dim filesys, file As Object, filenam As String, 路径 As String
Set filesys = CreateObject("Scripting.FileSystemObject")
路径 = CreateObject("Shell.Application").BrowseForFolder(0, "请选择文件夹", 0).Self.Path
For Each file In filesys.GetFolder(路径).Files
Filename = Filename & file.Name & Chr(10)
Next
MsgBox Filename, 64, "指定文件夹的文件列表"
End Sub
获取指定文件夹中的所有文件名
③ vb 默认的文件保存路径是什么
保存路径是当前可执行程序所在的文件夹。比如exe在d:workc estdemo.exe,哪么文件默认保存到d:workc est,利用VB文件夹列表框控件设置文件夹路径的方法:
1、新建一个标准工程。
④ VB 如何遍历文件夹下所有文件,高手请指教
窗体上有四个控件,命令按钮command1。列表框list1。驱动器列表Drive1。文件夹列表Dir1。
驱动器和文件夹列表是用来选择你想要搜索的文件夹。
程序运行时选中你想要搜索的文件夹,单击搜索按钮。该文件夹下面所有的文件及子文件夹里面的文件都列到列表框中。
将代码复制到窗体即可。代码如下:
Private Sub Command1_Click()
List1.Clear
sosuofile (Dir1.List(Dir1.ListIndex))
MsgBox "搜索完毕!,共找到" + Str(List1.ListCount) + "条记录。", vbOKOnly + vbExclamation, "提示"
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Sub sosuofile(MyPath As String)
Dim Myname As String
Dim dir_i() As String
Dim i, idir As Long
If Right(MyPath, 1) <> "\\" Then MyPath = MyPath + "\\"
Myname = Dir(MyPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
Do While Myname <> ""
If Myname <> "." And Myname <> ".." Then
If (GetAttr(MyPath & Myname) And vbDirectory) = vbDirectory Then '如果找到的是目录
idir = idir + 1
ReDim Preserve dir_i(idir) As String
dir_i(idir - 1) = Myname
Else: List1.AddItem "" & MyPath & " " & Myname '把找到的文件显示到列表框中
End If
End If
Myname = Dir '搜索下一项
Loop
For i = 0 To idir - 1
Call sosuofile(MyPath + dir_i(i))
Next i
ReDim dir_i(0) As String
End Sub
Private Sub Form_Load()
Command1.Caption = "搜索"
End Sub
⑤ VB怎样显示文件夹内所有的文件名称
VB可以使用FileListBox 控件来获取指定文件夹内的所有文件名。
FileListBox 控件,在运行时,在 Path 属性指定的目录中,FileListBox 控件将文件定位并列举出来。该控件用来显示所选择文件类型的文件列表。例如,可以在应用程序中创建对话框,通过它选择一个文件或者一组文件。
以下是组合使用DriveListBox 、控件DirListBox 控件和FileListBox 控件来获取硬盘下任何一个文件夹内的文件名。
PrivateSubDir1_Change()
File1.Path=Dir1.Path
EndSub
PrivateSubDrive1_Change()
Dir1.Path=Drive1.Drive
EndSub
PrivateSubFile1_Click()
DimiAsLong
Debug.Print"目录夹内存在"&File1.ListCount&"个文件。"
EndSub
⑥ 如何用vb计算文件夹内所有文件(包括子文件夹)
调用windows的Dir命令,生成一个列表文件,例如要计算C:\windows下有多少个文件和目录:
Dir
C:\windows\*.*
/s
>winList.txt
等命令执行完毕后,打开winlist.txt,最后显示的两行就是结果。
所列文件总数:
10709
个文件
3,328,172,320
字节
2684
个目录
1,155,395,584
可用字节
⑦ vb获取d:\的文件夹列表
' 显示 D:\ 目录下的名称。
MyPath = "D:\" ' 指定路径。
MyName = Dir(MyPath, vbDirectory) ' 找寻第一项。
Do While MyName <> "" ' 开始循环。
' 跳过当前的目录及上层目录。
If MyName <> "." And MyName <> ".." Then
' 使用位比较来确定 MyName 代表一目录。
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Debug.Print MyName ' 如果它是一个目录,将其名称显示出来。
End If
End If
MyName = Dir ' 查找下一个目录。
Loop
⑧ 如何用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 如何获取文件夹列表,显示在ListBox中,并将文件夹名称作为变量
Sub获得文件夹列表()
Dimf
f=Dir("D:aaa",16)'在括号内输入你指定的目录
DoWhilef<>""
IfInStr(f,".")=0Then
ListBox1.AddItemf
EndIf
f=Dir'查找下一个目录
Loop
EndSub