Search for File (how to)

G

Guest

Hello. Anyone know how to use the FileInfo class to search for a specific
file in a directory? My problem is the specific file I am looking for, but
the actual filename can contain alot of extra characters that are created
when a batch process takes place. for example, I know the root path and the
first few letters of the filename.

Root: C:\TestFolder
1st File to iterate: SThompson.123.exit.Read.out
2nd File to iterate: SThompson.email.Lg334.ini
OtherFile: SThompson.gif

So the information I have, stored in exposed public properties are the first
and last name (S Thompson)

The goal is to look for the .INI file ONLY. The problem is the rest of the
characters between the SThompson and the .INI change constantly b/c of batch
processing. Here is example I can think of

{
...... //path argument is stored from XML file

SomeClass sClass = new SomeClass
sClass.ReadFile() // method gets the properties
DirectoryInfo di = new DirectoryInfo(path);
FileInfo[] files2 = diSftp.GetFiles(i._Fname.Substring(1, 1).Trim +
i._Lname, "*.out);
 
G

Greg Young

You have the right idea .. just build up your path ...

SThompson*.ini should be able to get the file ...

You may also want to look at returning all the files and using a regexp
filter on the filenames returned which can be much more flexible than a
simple wildcarded filename

Cheers,

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