VB获取文件夹路径
展开全部
给你个VB遍历文件夹的代码吧
Private
Declare
Function
FindFirstFile
Lib
"kernel32"
Alias
"FindFirstFileA"
(ByVal
lpFileName
As
String,
lpFindFileData
As
WIN32_FIND_DATA)
As
Long
'查找下一个文件的API
Private
Declare
Function
FindNextFile
Lib
"kernel32"
Alias
"FindNextFileA"
(ByVal
hFindFile
As
Long,
lpFindFileData
As
WIN32_FIND_DATA)
As
Long
'获取文件属性的API
Private
Declare
Function
GetFileAttributes
Lib
"kernel32"
Alias
"GetFileAttributesA"
(ByVal
lpFileName
As
String)
As
Long
'关闭查找文件的API
Private
Declare
Function
FindClose
Lib
"kernel32"
(ByVal
hFindFile
As
Long)
As
Long
Const
MAX_PATH
=
260
Const
MAXDWORD
=
&HFFFF
Const
FILE_ATTRIBUTE_DIRECTORY
=
&H10
Private
Type
FILETIME
dwLowDateTime
As
Long
dwHighDateTime
As
Long
End
Type
Dim
tempstr
As
String
'定义类(用于查找文件)
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
Dim
filecount
As
Integer
Dim
dirs()
As
String
Dim
curr
As
Long
Dim
ss()
As
String
Private
Sub
Command1_Click()
tempstr
=
"c:"
searchdir
tempstr
filecount
=
0
End
Sub
Public
Function
searchdir(path
As
String)
Dim
WFD
As
WIN32_FIND_DATA
Dim
i
As
Long
Dim
temp
As
String
Dim
h
As
Long
Dim
zhaodao
As
Long
Dim
iindex
As
Integer
Dim
dirs()
As
String
Dim
l
As
Long
zhaodao
=
1
h
=
FindFirstFile(path
&
"\*.*",
WFD)
If
h
<>
-1
Then
While
zhaodao
zhaodao
=
1
temp
=
Left(WFD.cFileName,
InStr(WFD.cFileName,
Chr$(0))
-
1)
If
temp
<>
"."
And
temp
<>
".."
Then
If
WFD.dwFileAttributes
And
vbDirectory
Then
ReDim
Preserve
dirs(iindex)
dirs(iindex)
=
path
&
"\"
&
temp
iindex
=
iindex
+
1
ReDim
Preserve
ss(filecount)
ss(filecount)
=
path
&
"\"
&
temp
filecount
=
filecount
+
1
End
If
End
If
zhaodao
=
FindNextFile(h,
WFD)
Wend
End
If
FindClose
(h)
If
iindex
>
0
Then
For
i
=
0
To
iindex
-
1
Call
searchdir(dirs(i))
Next
i
End
If
End
Function
Private
Declare
Function
FindFirstFile
Lib
"kernel32"
Alias
"FindFirstFileA"
(ByVal
lpFileName
As
String,
lpFindFileData
As
WIN32_FIND_DATA)
As
Long
'查找下一个文件的API
Private
Declare
Function
FindNextFile
Lib
"kernel32"
Alias
"FindNextFileA"
(ByVal
hFindFile
As
Long,
lpFindFileData
As
WIN32_FIND_DATA)
As
Long
'获取文件属性的API
Private
Declare
Function
GetFileAttributes
Lib
"kernel32"
Alias
"GetFileAttributesA"
(ByVal
lpFileName
As
String)
As
Long
'关闭查找文件的API
Private
Declare
Function
FindClose
Lib
"kernel32"
(ByVal
hFindFile
As
Long)
As
Long
Const
MAX_PATH
=
260
Const
MAXDWORD
=
&HFFFF
Const
FILE_ATTRIBUTE_DIRECTORY
=
&H10
Private
Type
FILETIME
dwLowDateTime
As
Long
dwHighDateTime
As
Long
End
Type
Dim
tempstr
As
String
'定义类(用于查找文件)
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
Dim
filecount
As
Integer
Dim
dirs()
As
String
Dim
curr
As
Long
Dim
ss()
As
String
Private
Sub
Command1_Click()
tempstr
=
"c:"
searchdir
tempstr
filecount
=
0
End
Sub
Public
Function
searchdir(path
As
String)
Dim
WFD
As
WIN32_FIND_DATA
Dim
i
As
Long
Dim
temp
As
String
Dim
h
As
Long
Dim
zhaodao
As
Long
Dim
iindex
As
Integer
Dim
dirs()
As
String
Dim
l
As
Long
zhaodao
=
1
h
=
FindFirstFile(path
&
"\*.*",
WFD)
If
h
<>
-1
Then
While
zhaodao
zhaodao
=
1
temp
=
Left(WFD.cFileName,
InStr(WFD.cFileName,
Chr$(0))
-
1)
If
temp
<>
"."
And
temp
<>
".."
Then
If
WFD.dwFileAttributes
And
vbDirectory
Then
ReDim
Preserve
dirs(iindex)
dirs(iindex)
=
path
&
"\"
&
temp
iindex
=
iindex
+
1
ReDim
Preserve
ss(filecount)
ss(filecount)
=
path
&
"\"
&
temp
filecount
=
filecount
+
1
End
If
End
If
zhaodao
=
FindNextFile(h,
WFD)
Wend
End
If
FindClose
(h)
If
iindex
>
0
Then
For
i
=
0
To
iindex
-
1
Call
searchdir(dirs(i))
Next
i
End
If
End
Function
展开全部
只说
原理
。先建立FSO
对象遍历磁盘
查找名称为"baidu“的文件夹
,返回全路径
原理
。先建立FSO
对象遍历磁盘
查找名称为"baidu“的文件夹
,返回全路径
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用API遍历当前桌面已打开的子窗口,获得窗口句柄和ID,然后通过ID获得该文件夹的路径,总之一句话,你要实现的功能VB无法做到,API可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
做个time
时间定为200毫秒。检测鼠标当前位置所在的窗口ID。。再判断窗口里什么控件能显示路径的。。。。获取路径。。。
时间定为200毫秒。检测鼠标当前位置所在的窗口ID。。再判断窗口里什么控件能显示路径的。。。。获取路径。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是VB程序所在的文件夹路径吗?还是别的?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询