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
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-12-01
只说
原理
。先建立FSO
对象遍历磁盘
查找名称为"baidu“的文件夹
,返回全路径
第2个回答  2019-12-07
用API遍历当前桌面已打开的子窗口,获得窗口句柄和ID,然后通过ID获得该文件夹的路径,总之一句话,你要实现的功能VB无法做到,API可以
第3个回答  2020-05-07
做个time
时间定为200毫秒。检测鼠标当前位置所在的窗口ID。。再判断窗口里什么控件能显示路径的。。。。获取路径。。。
第4个回答  2019-12-10
是VB程序所在的文件夹路径吗?还是别的?
相似回答
大家正在搜