Learn how to a build a cloud-first strategyRegister Now


delete a file problem

Posted on 2006-04-26
Medium Priority
Last Modified: 2010-04-16
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") ) )


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 ?
Question by:Tech_Men
LVL 52

Accepted Solution

Carl Tawn earned 500 total points
ID: 16548477
LVL 64

Expert Comment

by:Fernando Soto
ID: 16548481
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".


Author Comment

ID: 16548568
i have done it like this :

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

thanks !!!

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question