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