Tech_Men
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 ?
DirectoryInfo dirInfo = new DirectoryInfo(FilePath);
foreach ( FileInfo f in dirInfo.GetFiles() )
{
if( f.Extension.Equals(".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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i have done it like this :
string Dir=System.IO.Path.GetDire ctoryName( FilePath);
DirectoryInfo dirInfo = new DirectoryInfo(Dir);
thanks !!!
string Dir=System.IO.Path.GetDire
DirectoryInfo dirInfo = new DirectoryInfo(Dir);
thanks !!!
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