我用循环遍历所有文件夹及其子文件夹的方法找到了所要找的文件,可是现在我想得到该文件的具体路径,我用了GetAbsolutePathName 方法来获得具体得路径可是出错了!!!
我把我做得工程放在“My Documents\yhy\遍历循环找文件\”中,而文件是在E:\歌曲库的文件夹下,我用了GetAbsolutePathName 方法之后,显示的具体路径就为“E:\My Documents\yhy\遍历循环找文件\10042.vox”,其实文件是在“E:\歌曲库\男歌星\原唱\10025.vox”,这个问题怎么解决啊...???
怎么才能得到正确的具体路径呢?用什么方法呢?
请各位高手指教!!
我把我做得工程放在“My Documents\yhy\遍历循环找文件\”中,而文件是在E:\歌曲库的文件夹下,我用了GetAbsolutePathName 方法之后,显示的具体路径就为“E:\My Documents\yhy\遍历循环找文件\10042.vox”,其实文件是在“E:\歌曲库\男歌星\原唱\10025.vox”,这个问题怎么解决啊...???
怎么才能得到正确的具体路径呢?用什么方法呢?
请各位高手指教!!
Dim bFound As Boolean
Dim iCount As Long
Dim fso As Scripting.FileSystemObjectPrivate Sub Command1_Click()
Set fso = CreateObject("Scripting.FileSystemObject")iCount = 0
CheckFolder "E:\歌曲库"
Debug.Print "查找到的文件数:" & iCountIf iCount > 0 Then
bFound = True
Else
bFound = False
End IfEnd SubSub CheckFolder(strPath As String)
Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File
Dim objSubdirs As Scripting.Folders
Dim objLoopFolder As Scripting.Folder
Dim sPath As String
Dim objAbsPath As StringDebug.Print "Checking directory" & strPath
Set objFolder = fso.GetFolder(strPath)For Each objFile In objFolder.Files
If Left(objFile.Name, 5) = "10042" Then
iCount = iCount + 1
sPath = objFile.Name
objAbsPath = fso.GetAbsolutePathName(sPath)
Debug.Print "文件具体路径:" & objAbsPath
End If
Next objFileSet objSubdirs = objFolder.SubFolders
For Each objLoopFolder In objSubdirs
CheckFolder objLoopFolder.Path
Next objLoopFolderSet objSubdirs = Nothing
Set objFolder = NothingEnd Sub
....
Static objAbsPath As String
For Each objFile In objFolder.Files
If Left(objFile.Name, 5) = "10042" Then
iCount = iCount + 1
sPath = objFile.Name
objAbsPath=objAbsPath & strPath & "?"
Debug.Print "文件具体路径:" & strPath
End If
Next objFile
....Set objSubdirs = Nothing
Set objFolder = NothingReturn objAbsPathEnd Sub
把objAbsPath值返回后,再用spilt()按“?”给它分开,就得到了所有符合条件的目录
我用的是GetParentFolderName方法,可是什么都找不到,请问是为什么?怎么找到父文件名呢?
谢谢各位了!!!
"D:\Software\VB6.0\MSDN98\98VS\2052\Setup"
提取"D:\Software\VB6.0\MSDN98\98VS\2052"