file searching and deleting

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
 
R

rodrigo

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 !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top