Link to home
Start Free TrialLog in
Avatar of Tech_Men
Tech_MenFlag for Israel

asked on

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 ?
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of Tech_Men

ASKER

i have done it like this :

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

thanks !!!