|
需要引用 Microsoft Scripting Runtime
1. 建一个窗体,上面放置文本框一个,名字为“驱动器名”,按钮一个,名字“command2”,列表框一个,名字“List3”
2. 输入下面的代码试试。
- Private Sub Command2_Click()
- Dim myDrive As String
- Dim Fs As New FileSystemObject
- Dim Fd As Folder, F As File
- On Error Resume Next
- myDrive = Trim(Me.驱动器名)
- If myDrive = "" Then
- MsgBox "请输入欲显示文件的驱动器名"
- Me.驱动器名.SetFocus
- Exit Sub
- End If
- If Right(myDrive, 2) <> ":" Then
- myDrive = myDrive & ":"
- End If
- Set Fd = Fs.GetFolder(myDrive)
- Me.List3.RowSource = ""
- For Each F In Fd.Files
- If (Not ((F.Attributes And System) = System) And (Not (F.Attributes And Hidden) = Hidden)) Then
- Me.List3.AddItem F.Name
- End If
- Next
- MsgBox "Finish"
- End Sub
- Private Sub Form_Load()
- Me.List3.RowSourceType = "Value List"
- Me.List3.RowSource = ""
- End Sub
复制代码 |
|