主题:[讨论]关于WFD和vbDirectory的关系
各位,看看下面代码,为什么返回值不一样啊?
Option Explicit
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * 260
cAlternate As String * 14
End Type
第一种代码:
Private Sub SearchFile()
Dim hFindFirstFile as long,hFindNextFile as long,WFD as WIN32_FIND_DATA
hFindFirstFile=FindFirstFile("c:\*.*",WFD)
If hFindFirstFile <> -1 then
hFindNextFile=-1
Do while hFindNextFile
if WFD.dwFileAttributes = vbDirectory then '请大家注意这里
list1.addItem left(WFD.cFileName,Instr(WFD.cFileName,chr(0)-1)
end if
hFindNextFile=FindNextFile(hFindFirstFile,WFD)
loop
End If
End Sub
第二种代码:
Private Sub SearchFile()
Dim hFindFirstFile as long,hFindNextFile as long,WFD as WIN32_FIND_DATA
hFindFirstFile=FindFirstFile("c:\*.*",WFD)
If hFindFirstFile <> -1 then
hFindNextFile=-1
Do while hFindNextFile
if (WFD.dwFileAttributes And vbDirectory) = vbDirectory then '请大家注意这里
list1.addItem left(WFD.cFileName,Instr(WFD.cFileName,chr(0)-1)
end if
hFindNextFile=FindNextFile(hFindFirstFile,WFD)
loop
End If
End Sub
在两种代码的执行结果中,list控件显示的目录不一样,就是第一种代码不会显示隐藏目录,而第二种代码可以显示隐藏目录,这是为什么呢?请大家一起讨论讨论。
Option Explicit
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * 260
cAlternate As String * 14
End Type
第一种代码:
Private Sub SearchFile()
Dim hFindFirstFile as long,hFindNextFile as long,WFD as WIN32_FIND_DATA
hFindFirstFile=FindFirstFile("c:\*.*",WFD)
If hFindFirstFile <> -1 then
hFindNextFile=-1
Do while hFindNextFile
if WFD.dwFileAttributes = vbDirectory then '请大家注意这里
list1.addItem left(WFD.cFileName,Instr(WFD.cFileName,chr(0)-1)
end if
hFindNextFile=FindNextFile(hFindFirstFile,WFD)
loop
End If
End Sub
第二种代码:
Private Sub SearchFile()
Dim hFindFirstFile as long,hFindNextFile as long,WFD as WIN32_FIND_DATA
hFindFirstFile=FindFirstFile("c:\*.*",WFD)
If hFindFirstFile <> -1 then
hFindNextFile=-1
Do while hFindNextFile
if (WFD.dwFileAttributes And vbDirectory) = vbDirectory then '请大家注意这里
list1.addItem left(WFD.cFileName,Instr(WFD.cFileName,chr(0)-1)
end if
hFindNextFile=FindNextFile(hFindFirstFile,WFD)
loop
End If
End Sub
在两种代码的执行结果中,list控件显示的目录不一样,就是第一种代码不会显示隐藏目录,而第二种代码可以显示隐藏目录,这是为什么呢?请大家一起讨论讨论。