msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FindFirstFile/FindNextFile

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB WinAPI
Author Message
Howard Kaikow



Joined: 04 Oct 2007
Posts: 468

PostPosted: Sat Feb 23, 2008 9:39 am    Post subject: FindFirstFile/FindNextFile Reply with quote

I've used the subject APIs at least umpteen times.

Currently, I am asking for all "*.csv" files.
No problem.
However, when I renamed one of the files, say, Pizza.csv-x, The APIs also
returned that file.

Am I perhaps incorrectly passing the type to FindFirstFile?
Or is this a "feature" of these APIs?

I'm using

hSearch = FindFirstFileW(StrPtr(path & sType), WFD)

with stType = "*.csv", and

Private Declare Function FindFirstFileW Lib "kernel32" _
(ByVal lpFileName As Long, lpFindFileData _
As WIN32_FIND_DATAW) As Long

In the interim, I have inserted code to discard files not having the exact
file type.

Archived from group: microsoft>public>vb>winapi
Back to top
View user's profile Send private message
Stuart McCall



Joined: 09 Nov 2007
Posts: 3

PostPosted: Sat Feb 23, 2008 4:40 pm    Post subject: Re: FindFirstFile/FindNextFile Reply with quote

"Howard Kaikow" wrote in message $fdIHA.4260@TK2MSFTNGP05.phx.gbl...
> I've used the subject APIs at least umpteen times.
>
> Currently, I am asking for all "*.csv" files.
> No problem.
> However, when I renamed one of the files, say, Pizza.csv-x, The APIs also
> returned that file.
>
> Am I perhaps incorrectly passing the type to FindFirstFile?
> Or is this a "feature" of these APIs?
>
> I'm using
>
> hSearch = FindFirstFileW(StrPtr(path & sType), WFD)
>
> with stType = "*.csv", and
>
> Private Declare Function FindFirstFileW Lib "kernel32" _
> (ByVal lpFileName As Long, lpFindFileData _
> As WIN32_FIND_DATAW) As Long
>
> In the interim, I have inserted code to discard files not having the exact
> file type.

Try using the Ansi version of FindFirstFile instead:

Private Declare Function FindFirstFileA Lib "kernel32" _
(ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_DATA) As Long
Back to top
View user's profile Send private message
Jim Mack



Joined: 04 Oct 2007
Posts: 735

PostPosted: Sat Feb 23, 2008 12:52 pm    Post subject: Re: FindFirstFile/FindNextFile Reply with quote

Howard Kaikow wrote:
> I've used the subject APIs at least umpteen times.
>
> Currently, I am asking for all "*.csv" files.
> No problem.
> However, when I renamed one of the files, say, Pizza.csv-x, The
> APIs also returned that file.
>
> Am I perhaps incorrectly passing the type to FindFirstFile?
> Or is this a "feature" of these APIs?

Your situation might be different, but the most common explanation for
why this sort of thing happens is that FindFirst/Next examine and
match both the long name and the short name.

In this case I'd guess the short name is PIZZA~1.CSV, which would
match. It's in the returned structure, so it would be easy to check.

--
Jim Mack
MicroDexterity Inc
www.microdexterity.com
Back to top
View user's profile Send private message
Thorsten Albers



Joined: 04 Oct 2007
Posts: 756

PostPosted: Sat Feb 23, 2008 10:40 am    Post subject: Re: FindFirstFile/FindNextFile Reply with quote

Howard Kaikow schrieb im Beitrag
...
> Currently, I am asking for all "*.csv" files.
> No problem.
> However, when I renamed one of the files, say, Pizza.csv-x, The APIs also
> returned that file.
> Am I perhaps incorrectly passing the type to FindFirstFile?
> Or is this a "feature" of these APIs?

FindFirst/NextFile() searches files by their long >>and<< short names.
With long file names the max. length of a file name extension is 255
characters, with short file names it is 3 characters. According to this the
long file name 'Pizza.csv-x' has a file name extension '.csv-x' which
exceeds the max. length of a short file name extension. MS has chosen to
>preserve the file name components< in such cases and shorten the file name
extension to the limit of FAT16, and so the short file name becomes
'PIZZA.CSV' (of course unless there is already an existing file
'PIZZA.CSV').

--
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
----------------------------------------------------------------------
Back to top
View user's profile Send private message
Howard Kaikow



Joined: 04 Oct 2007
Posts: 468

PostPosted: Sat Feb 23, 2008 6:54 pm    Post subject: Re: FindFirstFile/FindNextFile Reply with quote

"Stuart McCall" wrote in message$pvk$1$8300dec7@news.demon.co.uk...
> "Howard Kaikow" wrote in message
> $fdIHA.4260@TK2MSFTNGP05.phx.gbl...
> > I've used the subject APIs at least umpteen times.
> >
> > Currently, I am asking for all "*.csv" files.
> > No problem.
> > However, when I renamed one of the files, say, Pizza.csv-x, The APIs
also
> > returned that file.
> >
> > Am I perhaps incorrectly passing the type to FindFirstFile?
> > Or is this a "feature" of these APIs?
> >
> > I'm using
> >
> > hSearch = FindFirstFileW(StrPtr(path & sType), WFD)
> >
> > with stType = "*.csv", and
> >
> > Private Declare Function FindFirstFileW Lib "kernel32" _
> > (ByVal lpFileName As Long, lpFindFileData _
> > As WIN32_FIND_DATAW) As Long
> >
> > In the interim, I have inserted code to discard files not having the
exact
> > file type.
>
> Try using the Ansi version of FindFirstFile instead:
>
> Private Declare Function FindFirstFileA Lib "kernel32" _
> (ByVal lpFileName As String, _
> lpFindFileData As WIN32_FIND_DATA) As Long


Cannot do that.
Back to top
View user's profile Send private message
Howard Kaikow



Joined: 04 Oct 2007
Posts: 468

PostPosted: Sat Feb 23, 2008 7:24 pm    Post subject: Re: FindFirstFile/FindNextFile Reply with quote

"Thorsten Albers" wrote in message$5f30ef60$9f01a8c0@xyz...
> FindFirst/NextFile() searches files by their long >>and<< short names.
> With long file names the max. length of a file name extension is 255
> characters, with short file names it is 3 characters. According to this
the
> long file name 'Pizza.csv-x' has a file name extension '.csv-x' which
> exceeds the max. length of a short file name extension. MS has chosen to
> >preserve the file name components< in such cases and shorten the file
name
> extension to the limit of FAT16, and so the short file name becomes
> 'PIZZA.CSV' (of course unless there is already an existing file
> 'PIZZA.CSV').

So, it is a "feature"!

I'll get around it by using
If Mid$(FileName, InStrRev(FileName, ".") + 1) = _
Mid$(sType, InStrRev(sType, ".") + 1) Then
Back to top
View user's profile Send private message
MikeD



Joined: 04 Oct 2007
Posts: 3348

PostPosted: Sat Feb 23, 2008 8:04 pm    Post subject: Re: FindFirstFile/FindNextFile Reply with quote

"Howard Kaikow" wrote in message
news:%23dd1j1kdIHA.4172@TK2MSFTNGP02.phx.gbl...
> "Stuart McCall" wrote in message
> $pvk$1$8300dec7@news.demon.co.uk...
>> "Howard Kaikow" wrote in message
>> $fdIHA.4260@TK2MSFTNGP05.phx.gbl...
>> > I've used the subject APIs at least umpteen times.
>> >
>> > Currently, I am asking for all "*.csv" files.
>> > No problem.
>> > However, when I renamed one of the files, say, Pizza.csv-x, The APIs
> also
>> > returned that file.
>> >
>> > Am I perhaps incorrectly passing the type to FindFirstFile?
>> > Or is this a "feature" of these APIs?
>> >
>> > I'm using
>> >
>> > hSearch = FindFirstFileW(StrPtr(path & sType), WFD)
>> >
>> > with stType = "*.csv", and
>> >
>> > Private Declare Function FindFirstFileW Lib "kernel32" _
>> > (ByVal lpFileName As Long, lpFindFileData _
>> > As WIN32_FIND_DATAW) As Long
>> >
>> > In the interim, I have inserted code to discard files not having the
> exact
>> > file type.
>>
>> Try using the Ansi version of FindFirstFile instead:
>>
>> Private Declare Function FindFirstFileA Lib "kernel32" _
>> (ByVal lpFileName As String, _
>> lpFindFileData As WIN32_FIND_DATA) As Long
>
>
> Cannot do that.
>


While I can't see that suggestion solving the problem, why can't you?
Certainly you could just as something to *try* and see if it solves it. It'd
take a whole 5 seconds to do.

--
Mike
Microsoft MVP Visual Basic
Back to top
View user's profile Send private message
Howard Kaikow



Joined: 04 Oct 2007
Posts: 468

PostPosted: Sun Feb 24, 2008 12:38 am    Post subject: Re: FindFirstFile/FindNextFile Reply with quote

"MikeD" wrote in message
news:%23SPvHdldIHA.1824@TK2MSFTNGP02.phx.gbl...
> While I can't see that suggestion solving the problem, why can't you?
> Certainly you could just as something to *try* and see if it solves it.
It'd
> take a whole 5 seconds to do.

Because the result would not be functionally equivalent, and clearly would
not change things.

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
FindFirstFile/FindNextFile MSFT KB article Q185476 gives an example of how to search directories. Note there is a bug in the code as the FileSize variable in th button clickj event should be typed as Currency, instead of Long. Otherwise, the code works fine MOST of the time. For ex

FindNextFile - Finding file based on multiple patterns Hello! I am looking for a way how to add all MPEG Audio, Ogg Vorbis and Wave files to a ListView and found FindNextFile to be exactly what I need. However, I can only supply patterns like "*.wav", "*.mp1"... Is there a way to search for "*.wav; *.mp1; *.m

Problem with FindFirstFile API, Need help. Can anybody help a person I know (who doesn't have access to Newsgroups) with this issue. He is using VB6.0 with SP6 installed. He is using a FindFirstFile API from Now as far as he is concerned the API

FindFirstFile question How is the FindFirstFile function (from sorting the files ? I need an ascending sort for the found files ! Robertico

issues with FindFirstFile API call Hello everyone, I am programming in Visual Studio 2002, VB.net. I typically stick to version 1.0 of the framework for compatibility reasons. Recently, I ran into an issue that I couldn't solve with the framework. I am working with file paths that ex
Post new topic   Reply to topic    msvisual.com Forum Index -> VB WinAPI All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group