|
-
Dec 18th, 2001, 07:33 AM
#1
Thread Starter
New Member
FindFirstFile Problem
Hi
I have used the FindFirstFile api to locate files
The FindFirstFile api does not distinguish between the file extension (.htm) and (.html)
I know both are the same type of file but I need the FindFirstFile api to ignore the .html files and only find the .htm files is there any way to do this .
Thanks for the help
-
Dec 18th, 2001, 10:06 AM
#2
I never encountered this problem. Could you post your code?
PS: FindFirstFile changes behaviors a little bit with the advent of Win98.
-
Dec 18th, 2001, 10:46 AM
#3
Thread Starter
New Member
I use the program To find certain file types and then save their location in an array so I can copy them from one location to a new location
In the code below I have sent you the find button procedure and the FindFilesAPI function
I can if you want send you all the code for this app.
Find Button procedure
Private Sub Command1_Click()
Command2.Enabled = True
DirType = Combo1 'Used to find the file type (EG *.exe)
If DirType = "*.swf" Then
FPage = "Flash\"
Else
FPage = "shockwave\"
End If
Dim sPath As String, fStr As String
Dim fSize As Long
Dim fNum As Integer, dNum As Integer
Screen.MousePointer = vbHourglass
List1.Clear
sPath = sBuffer ' this text string is from the brouse button
'it is declared in the general declarations area
'fStr = Text2.Text
fStr = Combo1
fSize = FindFilesAPI(sPath, fStr, fNum, dNum)
Text3.Text = "number of files found" & " " & fNum
Screen.MousePointer = vbDefault
End Sub
FindFilesAPI function
Function FindFilesAPI(path As String, SearchStr As String, FileCount As Integer, DirCount As Integer)
Dim fName As String
Dim dName As String
Dim dNames() As String
Dim nDir As Integer
Dim i As Integer
Dim hSearch As Long
Dim WFD As WIN32_FIND_DATA
Dim Cont As Integer
If Right(path, 1) <> "\" Then path = path & "\"
nDir = 0
ReDim dNames(nDir)
Cont = True
hSearch = FindFirstFile(path & "*", WFD)
If hSearch <> INVALID_HANDLE_VALUE Then
Do While Cont
dName = StripNulls(WFD.cFileName)
If (dName <> ".") And (dName <> "..") Then
If GetFileAttributes(path & dName) And FILE_ATTRIBUTE_DIRECTORY Then
dNames(nDir) = dName
DirCount = DirCount + 1
nDir = nDir + 1
ReDim Preserve dNames(nDir)
End If
End If
Cont = FindNextFile(hSearch, WFD)
Loop
Cont = FindClose(hSearch)
End If
hSearch = FindFirstFile(path & SearchStr, WFD)
Cont = True
If hSearch <> INVALID_HANDLE_VALUE Then
While Cont
fName = StripNulls(WFD.cFileName)
If (fName <> ".") And (fName <> "..") Then
FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
FileCount = FileCount + 1
List1.AddItem path & fName
ReDim Preserve narray(array_count)
narray(array_count) = path & fName
array_count = array_count + 1
maxsize = array_count
End If
Cont = FindNextFile(hSearch, WFD)
Wend
Cont = FindClose(hSearch)
End If
If nDir > 0 Then
For i = 0 To nDir - 1
FindFilesAPI = FindFilesAPI + FindFilesAPI(path & dNames(i) & "\", SearchStr, FileCount, DirCount)
Next i
End If
End Function
-
Dec 18th, 2001, 10:57 AM
#4
Here is why:
hSearch = FindFirstFile(path & "*", WFD)
By appending the asterisk, you ask it to find *.htm*
-
Dec 18th, 2001, 11:19 AM
#5
Thread Starter
New Member
If I remove the ("*") no files are found
-
Dec 18th, 2001, 11:26 AM
#6
IF you want it to list ALL files, yes.
Otherwise you will have reformat the file specification to something like "path\*.htm" <--- no trailing asterisk.
That is, if you want to differentiate between .htm and .html
What I'm telling you is that the call FindFirstFile is doing what you are telling it to do. Which, it seems, is NOT what you want it to do.
-
Dec 18th, 2001, 11:39 AM
#7
Thread Starter
New Member
I have a list of file extension types listed in a combo box (Combo1 )
for EG (*.swf, *.dcr, *.htm)
The program runs fine for the first two types but when it comes to the *.htm it also finds the *.html file types
However If I tell it to find *.html it only finds them and not the htm files.
In short i have know idea what the problem is
-
Dec 18th, 2001, 11:59 AM
#8
Okay. I see. But the code you posted, as posted, has a problem.
Next question: are you using win95? If so, you may have problems with file extensions & wildcard characters. Sounds like it.
This is one of several problems:
http://support.microsoft.com/default...;EN-US;q130860
It shows a workaround.
-
Dec 18th, 2001, 12:23 PM
#9
Thread Starter
New Member
Yes i am using W95 but I also tested it on W98
-
Dec 18th, 2001, 02:57 PM
#10
The reason is explained in the MSDN reference.
If not a problem then:
use *.ht? to get htm files, *.htm? to get html
Force the number of characters to consider.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|