Error in System.IO.Directory.GetFiles?

M

Mobile Boy

Hello group,



When using "*.doc" as searchpattern, Getfiles is filling the enumerator with
doc-files but also incorrectly with docx files.
Try this little piece of code to reproduce this issue.
Why does "*.doc" ends in a list of both, doc-files and docx-files?



Dim En As IEnumerator

Dim FoundFile As String

En = System.IO.Directory.GetFiles(_Directory, "*.doc").GetEnumerator()

While En.MoveNext

FoundFile = System.Convert.ToString(En.Current.ToString)



End While





Best regards,

Mobile boy
 
T

Tom Shelton

Mobile Boy wrote on 1/9/2013 :
Hello group,



When using "*.doc" as searchpattern, Getfiles is filling the
enumerator with doc-files but also incorrectly with docx files.
Try this little piece of code to reproduce this issue.
Why does "*.doc" ends in a list of both, doc-files and docx-files?



Dim En As IEnumerator

Dim FoundFile As String

En = System.IO.Directory.GetFiles(_Directory,
"*.doc").GetEnumerator()

While En.MoveNext

FoundFile = System.Convert.ToString(En.Current.ToString)



End While





Best regards,

Mobile boy

Read the documentation -
http://msdn.microsoft.com/en-US/library/wz42302f(v=vs.110).aspx

In the notes:

<quote>
A searchPattern with a file extension of exactly three characters
returns files having an extension of three or more characters, where
the first three characters match the file extension specified in the
searchPattern.
</quote>

In other words, it's by design.
 
M

Mobile Boy

OK, Thank you Tom for your answer.
So you have to build in an extra check to see wetherthe extension is doc or
docx. Good to know!

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top