读取一个文件夹下的所有文件名如何
是用 fso
Dim fso
Dim fn As String
Private Sub Command1_Click()
Dim fd As String
Set fso = CreateObject("Scripting。 FileSystemObject")
fd = "C:\x"
Call getFilenm(fd)
MsgBox fn
End Sub
Function getFilenm(fdnm As String)
Dim obFd, fl, sfd
Set obFd = fso。 GetFolder(fdnm)
Fo...全部
是用 fso
Dim fso
Dim fn As String
Private Sub Command1_Click()
Dim fd As String
Set fso = CreateObject("Scripting。
FileSystemObject")
fd = "C:\x"
Call getFilenm(fd)
MsgBox fn
End Sub
Function getFilenm(fdnm As String)
Dim obFd, fl, sfd
Set obFd = fso。
GetFolder(fdnm)
For Each fl In obFd。Files
fn = fn & fl。Name & Chr(10)
Next
If obFd。
SubFolders。Count > 0 Then
For Each sfd In obFd。SubFolders
Call getFilenm(sfd。
Path)
Next
End If
End Function
---------------------------------------------------------------
'----------------------------------------------------------------------------
'
'Author:lihonggen0
'Date:2003-6-20
'功能:把一个目录下的所有文件的文件名导出到execl表
'----------------------------------------------------------------------------
Private Function AutoListFiles(ByVal sDirName As String, ByVal FileFilter As String) As Boolean
On Error GoTo RF_ERROR
Dim xlApp As Excel。
Application
Dim xlBook As Excel。Workbook
Dim xlSheet As Excel。Worksheet
Set xlApp = CreateObject("Excel。
Application")
Set xlBook = xlApp。Workbooks。Add
Set xlSheet = xlBook。Worksheets(1)
Dim sName As String, sFile As String, sExt As String
Dim sDirList() As String, iDirNum As Integer, I As Integer
'首先枚举所有文件
sFile = Dir(sDirName + FileFilter, vbNormal + vbArchive + vbHidden)
I = 1
Do While Len(sFile) > 0
sFile = UCase(Trim(sFile))
Debug。
Print sFile
xlSheet。Cells(I, 2)。Value = sFile
I = I + 1
sFile = Dir '下一个文件
Loop
xlApp。
Application。Visible = True
'交还控制给Excel
Set xlApp = Nothing
RF_EXIT:
AutoListFiles = True
Set xlApp = Nothing
Exit Function
RF_ERROR:
MsgBox Err。
Description, vbCritical, ""
Resume RF_EXIT
End Function
Private Sub Command1_Click()
Dim bln As Boolean
'将F:\盘根目录下的所有文件和目录列出来
bln = AutoListFiles("f:\", "*。
*")
End Sub。收起