delete a file problem

hi there this is the code :

DirectoryInfo dirInfo = new DirectoryInfo(FilePath);
                  
                  foreach ( FileInfo f in dirInfo.GetFiles() )
                  {
                        if( f.Extension.Equals(".doc") && (f.Name.Equals("Presto.doc") ) )
                        {
                              f.Delete();
                        }

                  }

the FilePath hold this line : @C:\1\Presto.doc
i need to send only the Dir whitout the file name in order the delete will work
how can i remove the Presto.doc from the Dir Path ?
Tech_MenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
System.IO.Path.GetDirectoryName(FilePath)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
Hi Tech_Men;

The code you have posted does work, Itested it. What seems to be the problem is the FilePath you are using. It should be the directory name only. For example in your example the FilePath should be @"C:\1" and not @"C:\1\Presto.doc".

Fernando
Tech_MenAuthor Commented:
i have done it like this :

string Dir=System.IO.Path.GetDirectoryName(FilePath);
                  DirectoryInfo dirInfo = new DirectoryInfo(Dir);

thanks !!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.