FileSearch对象。通配符奇怪的结果 [英] FileSearch Object. Strange result with Wildcards

查看:73
本文介绍了FileSearch对象。通配符奇怪的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Win98和WinXP上访问8


我在

FileSearch对象的.Filename属性中遇到通配符问题,给出了不同的结果win98和XP。我已经成功地使用win98中的FileSearch来填充文件名为

的数组自1998年以来没有问题。


从97帮助:

(FileSearch对象的Filename属性)

------------------- -------

返回或设置文件搜索期间要查找的文件的名称。该文件的

名称可能包括*(星号)或? (问号)

通配符。使用问号通配符匹配任何单个字符。

例如,键入gr?y以匹配灰色和灰色。和灰色。使用星号

通配符匹配任意数量的字符。例如,键入* .txt以查找具有.TXT扩展名的所有文件。

。读写字符串。

----------------------------


现在说得很清楚,就是我想要的东西,以及我想要的


这就是我在机器上得到的东西来自Access和Excel。,* with或

没有* a参考MSO97.DLL没有引用我不能使用

常量,如msoFileTypeAllFiles,但是参考我可以找到

msoFileTypeAllFiles = 1并使用1.这是我需要的唯一常量,

和所有文件选择路径的下一步应该是

..Filename通配符。 (SortBy,SortOrder,

AlwaysAccurate)的.Execute默认值是我想要的,虽然我注意到虽然帮助

表示SortBy" ...可以是以下MsoSortOrder常量之一:

msoSortOrderAscending或msoSortOrderDescending,"当我省略SortBy时,我得到了

未排序的结果。那很好。


然而,当我的朋友Kirk在另一个城市使用

Office 8在XP下运行它时,他会得到不同的结果。文件规范* .doc; * .txt

不返回任何内容,尽管有些文件符合这些规范。

从文件搜索 - 打开数据库 - 高级使用那些规格完美无缺。

完美无缺。 (帮助表明FileSearch对象用于那个

搜索。)


我不知所措。 Kirk设置了MSO97.DLL参考并将其移动到参考列表中,因为它会坚持下去。


我们的基准是搜索单个星号。我返回所有文件,他,

唉,什么也得不到。


为了它的价值,我会粘贴我相当苛刻的测试代码。

ShowMe应该可以工作,但是testgFindFiles()需要一个有效的路径。


任何人都可以告诉我为何选择*。doc; *。 TXT"或者*的规格会不会在XP机器上返回任何内容?


干杯,

艾伦

''# ###############

选项比较数据库

选项明确

公共gFoundFiles As Variant


函数gFindFiles(findWhere,findWhat,_

可选DoSubFolders As Boolean = True)As Variant

''对Office C的引用: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ br />
''Dim msg''用于调试。

Dim I

''使用Office.FileSearch

使用应用程序.FileSearch

.NewSearch

''。LookIn =" n:\ aa \" ''强制反斜杠?应用程序。

如果.LookIn =" C:\ My Documents"然后停止

''当findWhere不存在时,默认为我的文件

''也许如果Dir ......之前With ..

.LookIn = findWhere

.SearchSubFolders = DoSubFolders

.MatchAllWordForms = False

.MatchTextExactly = False

.FileType = 1''msoFileTypeAllFiles

.Filename = findWhat''" * .doc; * .txt"

。执行''msoSortBy。 ..''RetVal可能很有用。

ReDim aFiles(。FINFiles.Count)

For I = 1 To StatFiles.Count

''msg = msg& .Files(I)& vbCrLf

aFiles(I)= .files(I)

下一页我

结束

''AlanPrint msg

gFindFiles = aFiles

''gFoundFiles = aFiles

删除aFiles

结束功能

函数fixFindWhat(findWhat)

Select Case findWhat

Case IsNull(findWhat)," *"," *。*"

fixFindWhat =""

Case Else

fixFindWhat = findWhat

结束选择

结束功能


Sub testgFindFiles()

Dim Gottem

Dim thePath

''thePath =" ;我:\"

thePath =" H:\ CDList \" ''Kirk,使用任何有用的东西。

Gottem = gFindFiles(thePath," * .mp3")

Debug.Print UBound(Gottem)," * .mp3" ;

Gottem = gFindFiles(thePath," * .wav")

Debug.Print UBound(Gottem)," * .wav"

Gottem = gFindFiles(thePath," * .mp3; * .wav")

Debug.Print UBound(Gottem)," * .mp3; * .wav"

Gottem = gFindFiles(thePath," *。*")

Debug.Print UBound(Gottem)," *。*"

Gottem = gFindFiles(thePath," *")

Debug.Print UBound(Gottem)," *"

Gottem = gFindFiles(thePath,"")

Debug.Print UBound(Gottem),"

Debug.Print完成

Erase Gottem

End Sub


Sub ShowMe()

Dim Gottem,msg

Dim thePath $,我

thePath =" c:\windows \"

Gottem = gFindFiles(thePath," * .txt; *。ini&q uot;,False)

For I = 1 To UBound(Gottem)

msg = msg& Gottem(I)& vbCrLf

下一页

AlanPrint消息

End Sub

Sub AlanPrint(msg)

Dim PrintPlace $

PrintPlace $ = Environ(" temp")& " \ AlanTemp.txt"

Dim FileNum As Integer

FileNum = FreeFile

打开PrintPlace $输出为#FileNum
打印#FileNum,msg

关闭FileNum

PrintPlace $ =" notepad.exe" &安培; PrintPlace $

msg = Shell(PrintPlace $,1)''收缩消息变量

End Sub

''###### ##########

Access 8 on Win98 and WinXP

I''m having trouble with wildcards in the .Filename property of the
FileSearch Object giving different results on win98 and XP. I''ve been
successfully using FileSearch in win98 to fill an array with filenames with
no problems since about 1998.

From the 97 Help:
(The Filename Property of the FileSearch object)
--------------------------
Returns or sets the name of the file to look for during a file search. The
name of the file may include the * (asterisk) or ? (question mark)
wildcards. Use the question mark wildcard to match any single character.
For example, type gr?y to match both "gray" and "grey." Use the asterisk
wildcard to match any number of characters. For example, type *.txt to find
all files that have the .TXT extension. Read-write String.
----------------------------

Now that''s fairly well spelled out, just what I want and just what I
expected.
It''s what I get on my machine both from Access and Excel., *with or
without* a Reference to MSO97.DLL Without the Reference I can''t use the
constants such as msoFileTypeAllFiles, but with the Reference I can find
that msoFileTypeAllFiles = 1 and use 1. That''s the only constant I need,
and with "All Files" the next step in the selection path should be the
..Filename wildcard. The .Execute defaults for (SortBy, SortOrder,
AlwaysAccurate) are what I want, though I''ve noticed that although Help
says SortBy " ... can be either of the following MsoSortOrder constants:
msoSortOrderAscending or msoSortOrderDescending," when I omit SortBy I get
unsorted results. That''s fine.

However, when my friend Kirk in another city runs it on his machine using
Office 8 under XP, he gets different results. A filespec of "*.doc;*.txt"
returns nothing, although there are files which match those specs.
Searching from File - Open Database - Advanced using those specs works
perfectly. (The Help indicates the FileSearch Object is used for that
search.)

I''m at a loss. Kirk has set the MSO97.DLL Reference and moved it as far up
the Reference list as it will stick.

Our "benchmark" is a search for a single asterisk. I return all files, he,
alas, gets nothing.

For what it''s worth I''ll paste my rather butchered test code.
ShowMe should work, but testgFindFiles() will need a valid path.

Can anyone tell my why a spec of "*.doc;*.txt" or a spec of "*" would
return nothing on an XP machine?

Cheers,
Alan
''################
Option Compare Database
Option Explicit
Public gFoundFiles As Variant

Function gFindFiles(findWhere, findWhat, _
Optional DoSubFolders As Boolean = True) As Variant
''Reference to Office C:\OFFICE97\OFFICE\MSO97.DLL

''findWhat = fixFindWhat(findWhat) '' For Kirk
Dim aFiles() As Variant
''Dim msg '' for Debug.
Dim I
''With Office.FileSearch
With Application.FileSearch
.NewSearch
''.LookIn = "n:\aa\" ''Force Backslash?Application.
If .LookIn = "C:\My Documents" Then Stop
''When findWhere doesn''t exist, default is "My Documents"
''Maybe If Dir ... before "With ..
.LookIn = findWhere
.SearchSubFolders = DoSubFolders
.MatchAllWordForms = False
.MatchTextExactly = False
.FileType = 1 ''msoFileTypeAllFiles
.Filename = findWhat ''"*.doc;*.txt"
.Execute ''msoSortBy... ''RetVal could be useful.
ReDim aFiles(.FoundFiles.Count)
For I = 1 To .FoundFiles.Count
''msg = msg & .FoundFiles(I) & vbCrLf
aFiles(I) = .FoundFiles(I)
Next I
End With
'' AlanPrint msg
gFindFiles = aFiles
''gFoundFiles = aFiles
Erase aFiles
End Function
Function fixFindWhat(findWhat)
Select Case findWhat
Case IsNull(findWhat), "*", "*.*"
fixFindWhat = ""
Case Else
fixFindWhat = findWhat
End Select
End Function

Sub testgFindFiles()
Dim Gottem
Dim thePath
''thePath = "I:\"
thePath = "H:\CDList\" ''Kirk, use whatever works.
Gottem = gFindFiles(thePath, "*.mp3")
Debug.Print UBound(Gottem), "*.mp3"
Gottem = gFindFiles(thePath, "*.wav")
Debug.Print UBound(Gottem), "*.wav"
Gottem = gFindFiles(thePath, "*.mp3;*.wav")
Debug.Print UBound(Gottem), "*.mp3;*.wav"
Gottem = gFindFiles(thePath, "*.*")
Debug.Print UBound(Gottem), "*.*"
Gottem = gFindFiles(thePath, "*")
Debug.Print UBound(Gottem), "*"
Gottem = gFindFiles(thePath, "")
Debug.Print UBound(Gottem), ""
Debug.Print "Done"
Erase Gottem
End Sub

Sub ShowMe()
Dim Gottem, msg
Dim thePath$, I
thePath = "c:\windows\"
Gottem = gFindFiles(thePath, "*.txt;*.ini", False)
For I = 1 To UBound(Gottem)
msg = msg & Gottem(I) & vbCrLf
Next
AlanPrint msg
End Sub
Sub AlanPrint(msg)
Dim PrintPlace$
PrintPlace$ = Environ("temp") & "\AlanTemp.txt"
Dim FileNum As Integer
FileNum = FreeFile
Open PrintPlace$ For Output As #FileNum
Print #FileNum, msg
Close FileNum
PrintPlace$ = "notepad.exe " & PrintPlace$
msg = Shell(PrintPlace$, 1) ''shrink msg variant
End Sub
''################

推荐答案

,我

thePath =" c:\windows \"

Gottem = gFindFiles(thePath," * .txt; * .ini",False)

For I = 1 To UBound(Gottem)

msg = msg& Gottem(I)& vbCrLf

下一页

AlanPrint消息

End Sub

Sub AlanPrint(msg)

Dim PrintPlace
, I
thePath = "c:\windows\"
Gottem = gFindFiles(thePath, "*.txt;*.ini", False)
For I = 1 To UBound(Gottem)
msg = msg & Gottem(I) & vbCrLf
Next
AlanPrint msg
End Sub
Sub AlanPrint(msg)
Dim PrintPlace




PrintPlace

PrintPlace


= Environ(" temp")& " \ AlanTemp.txt"

Dim FileNum As Integer

FileNum = FreeFile

打开PrintPlace
= Environ("temp") & "\AlanTemp.txt"
Dim FileNum As Integer
FileNum = FreeFile
Open PrintPlace


这篇关于FileSearch对象。通配符奇怪的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆