Search for File (how to)

  • Thread starter Thread starter Guest
  • Start date Start date
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);
 
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#
 
Back
Top