delete a file problem

Posted on 2006-04-26
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

    LVL 62

    Expert Comment

    by:Fernando Soto
    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

    i have done it like this :

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

    thanks !!!

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now