Problems using Directory.GetFiles

G

Guest

Hello,

I am having some difficulties using Directory.GetFiles. I have a directory
with contains:

file1.fmt
file2.fmt
file3.fmt
file4.fmt_
file5.fmt_

When i use Directory.GetFile(directory, "*.fmt") i returns all the filenames
instead of just the .fmt files.

Is there a function i can call that only returns the filenames with the
extension i specify?

Thank you
 
K

Kevin Spencer

I don't know what you're doing wrong, but it should only be returning the
files with a ".fmt" extension.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
G

Guest

I am doing the following:

String [] filenames = System.IO.Directory.GetFiles(directory, "*.fmt");

The filenames array definitely contains the 5 entries, filenames with both
extension .fmt and .fmt_
 
S

Stephen Ahn

Daniel,

Directory.GetFiles makes calls to Win32's native FindFirst/FindNext
routines. The way I understand it, the search condition of these routines
works for *both* long and short (8.3) filenames. Since "file4.fmt_" has a
short filename of "file4.fmt", it matched. If you go into a Windows command
shell, and perform "DIR *.fmt", you should see the same thing happening.
Is there a function i can call that only returns the filenames with the
extension i specify?

You might have to write your own code which wraps calls around
Directory.GetFiles to do this extra filtering.

HTH,
Stephen
 
G

Greg Young

I have for some time now used a wrapper class which used regexps to do the
filterring as there are alot of odd bugs in the old find* apis ..

basically you just call into return all files then filter using the regexp.

Greg Young
MVP - C#
 

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