打印#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 theFileSearch Object giving different results on win98 and XP. I''ve beensuccessfully using FileSearch in win98 to fill an array with filenames withno 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. Thename 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 asteriskwildcard to match any number of characters. For example, type *.txt to findall files that have the .TXT extension. Read-write String.---------------------------- Now that''s fairly well spelled out, just what I want and just what Iexpected.It''s what I get on my machine both from Access and Excel., *with orwithout* a Reference to MSO97.DLL Without the Reference I can''t use theconstants such as msoFileTypeAllFiles, but with the Reference I can findthat 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 Helpsays SortBy " ... can be either of the following MsoSortOrder constants:msoSortOrderAscending or msoSortOrderDescending," when I omit SortBy I getunsorted results. That''s fine. However, when my friend Kirk in another city runs it on his machine usingOffice 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 worksperfectly. (The Help indicates the FileSearch Object is used for thatsearch.) I''m at a loss. Kirk has set the MSO97.DLL Reference and moved it as far upthe 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 "*" wouldreturn nothing on an XP machine? Cheers,Alan''################Option Compare DatabaseOption ExplicitPublic 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 KirkDim aFiles() As Variant''Dim msg '' for Debug.Dim I''With Office.FileSearchWith 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) & vbCrLfaFiles(I) = .FoundFiles(I)Next IEnd With'' AlanPrint msggFindFiles = aFiles''gFoundFiles = aFilesErase aFilesEnd FunctionFunction fixFindWhat(findWhat)Select Case findWhatCase IsNull(findWhat), "*", "*.*"fixFindWhat = ""Case ElsefixFindWhat = findWhatEnd SelectEnd Function Sub testgFindFiles()Dim GottemDim 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 GottemEnd Sub Sub ShowMe()Dim Gottem, msgDim thePath$, IthePath = "c:\windows\"Gottem = gFindFiles(thePath, "*.txt;*.ini", False)For I = 1 To UBound(Gottem)msg = msg & Gottem(I) & vbCrLfNextAlanPrint msgEnd SubSub AlanPrint(msg)Dim PrintPlace$PrintPlace$ = Environ("temp") & "\AlanTemp.txt"Dim FileNum As IntegerFileNum = FreeFileOpen PrintPlace$ For Output As #FileNumPrint #FileNum, msgClose FileNumPrintPlace$ = "notepad.exe " & PrintPlace$msg = Shell(PrintPlace$, 1) ''shrink msg variantEnd 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 , IthePath = "c:\windows\"Gottem = gFindFiles(thePath, "*.txt;*.ini", False)For I = 1 To UBound(Gottem)msg = msg & Gottem(I) & vbCrLfNextAlanPrint msgEnd SubSub AlanPrint(msg)Dim PrintPlace PrintPlace PrintPlace = Environ(" temp")& " \ AlanTemp.txt" Dim FileNum As Integer FileNum = FreeFile 打开PrintPlace = Environ("temp") & "\AlanTemp.txt"Dim FileNum As IntegerFileNum = FreeFileOpen PrintPlace 这篇关于FileSearch对象。通配符奇怪的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-19 09:35