按键精灵怎么读取指定目录下所有文件夹名

时间:2016/5/30 13:59:32  作者:Mho  来源:守望幸福  查看:56897  评论:0
内容摘要:按键精灵怎么读取指定目录下所有文件夹名?
按键精灵怎么读取指定目录下所有文件夹名?

思路:

读取文件夹名,参考实例如下:
文件夹="C:\百度\" 
Set F = CreateObject("Scripting.FileSystemObject")
If Not F.FolderExists(文件夹) Then
MsgBox "未检测到文件夹"
End If
Set oF = F.GetFolder(文件夹)
For Each a In oF.Files
MSGBOX a.NAME
NEXT



--------------------


完整例子:

Function FindAllFiles(FolderPath)
    Dim AllFiles,fso,Folder,f,files
    AllFiles = ""
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set Folder = fso.getfolder(FolderPath)
    Set files = Folder.files
    For Each f In files
        AllFiles = AllFiles & f.name & ","
    Next
    Set fso = Nothing
    FindAllFiles = Split(AllFiles, ",")
End Function
 
//下面是调用方法:
FileEx = FindAllFiles(文件路径)  //文件路径是字符串,要加双撇
If UBound(FileEx) > 0 Then 
 For i = 0 To UBound(FileEx) - 1
  MessageBox FileEx(i)
 Next
Else 
 MessageBox "文件夹没有文件"
End If


--------------------



相关评论

图库精选