|
| Author |
Message |
Howard Kaikow
Joined: 04 Oct 2007 Posts: 468
|
Posted: Sat Feb 23, 2008 9:39 am Post subject: FindFirstFile/FindNextFile |
|
|
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 |
|
 |
Stuart McCall
Joined: 09 Nov 2007 Posts: 3
|
Posted: Sat Feb 23, 2008 4:40 pm Post subject: Re: FindFirstFile/FindNextFile |
|
|
"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 |
|
 |
Jim Mack
Joined: 04 Oct 2007 Posts: 735
|
Posted: Sat Feb 23, 2008 12:52 pm Post subject: Re: FindFirstFile/FindNextFile |
|
|
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 |
|
 |
Thorsten Albers
Joined: 04 Oct 2007 Posts: 756
|
Posted: Sat Feb 23, 2008 10:40 am Post subject: Re: FindFirstFile/FindNextFile |
|
|
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 |
|
 |
Howard Kaikow
Joined: 04 Oct 2007 Posts: 468
|
Posted: Sat Feb 23, 2008 6:54 pm Post subject: Re: FindFirstFile/FindNextFile |
|
|
"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 |
|
 |
Howard Kaikow
Joined: 04 Oct 2007 Posts: 468
|
Posted: Sat Feb 23, 2008 7:24 pm Post subject: Re: FindFirstFile/FindNextFile |
|
|
"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 |
|
 |
MikeD
Joined: 04 Oct 2007 Posts: 3348
|
Posted: Sat Feb 23, 2008 8:04 pm Post subject: Re: FindFirstFile/FindNextFile |
|
|
"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 |
|
 |
Howard Kaikow
Joined: 04 Oct 2007 Posts: 468
|
Posted: Sun Feb 24, 2008 12:38 am Post subject: Re: FindFirstFile/FindNextFile |
|
|
"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 |
|
 |
|
|