作者:绿色风
分类:
时间:2022-08-17
浏览:158
楼主 0Mouse |
Q:如何运用API函数判断指定的完整路径是否为文件夹呢? A:先判断指定路径的文件是否存在,再判断是否为文件夹类型,代码如下:
- Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
- (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
- Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
- Private Const MAX_PATH = 260
- Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
- Private Const INVALID_HANDLE_VALUE As Long = -1
- 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 * MAX_PATH
- cAlternate As String * 14
- End Type
- Sub 运用API函数判断指定的完整路径是否为文件夹()
- Dim sFullName As String
- Dim hFileHandle As Long
- Dim WFDFileData As WIN32_FIND_DATA
- sFullName = ThisWorkbook.Path & "\xqoa"
- hFileHandle = FindFirstFile(sFullName, WFDFileData)
- If hFileHandle = INVALID_HANDLE_VALUE Then
- MsgBox "不存在与指定路径一致的文件(夹)"
- Exit Sub
- End If
- If WFDFileData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY Then MsgBox "指定路径是文件夹"
- FindClose hFileHandle
- End Sub
附件: 运用API函数判断指定的完整路径是否为文件夹.rar |
2楼 13641096715 |
|
3楼 老糊涂 |
收藏了 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一