file searching and deleting

  • Thread starter Thread starter Nico Vrouwe
  • Start date Start date
N

Nico Vrouwe

Hi,

You'd have to do a recursive search, something like this (not tested)

public static void FindAndDelete( DirectoryInfo dirInfo, string pattern )
{
foreach( DirectoryInfo di in dirInfo.GetDirectories() )
FindAndDelete( di, pattern );
foreach( FileInfo fi in dirInfo.GetFiles( pattern ) )
fi.Delete();
}

then call it like:
FindAndDelete( new DirectoryInfo( @"C:\", "*.tmp" );
where C:\ is the dir where you want to start searching, and *.tmp the files
you want to delete.

Hope this helps,

Nico Vrouwe
 
hi all...

how could i make a exe that searches the hd for a specific file that can
be in random folders, and delete it when find it.

how can i accomplish that in c# ?
any link ? source code to deal with file manipulation ?


thanks !
 
Back
Top