hello,
i need code to delete all files in my folder application except tow files
how can i do that?
For example:
my folder application "Debug"
file 1 = Debug.exe
file 2 = WindowsFormsApplication1.vshost.exe.manifest
blah blah blah is here! blah blah » Close
1 answers
Try something like this:
EDIT
To delete subdirectories as well, including any files or subdirectories which they contain, then add this code to the above:
If you only want to get rid of subdirectories, provided they have no files in them, then change subDir.Delete(true) to subDir.Delete(false).
Notice that as the code stands it won't prevent deletion of excluded files which are in subdirectories rather than the parent directory. If you want to do this, I'll have to rewrite it to look at each subdirectory recursively.
answered one year ago by:
17279
153
thank you it work , but why i can't delete folder in debug?
17279
FileInfo only deals with files. If you want to delete subdirectories as well, then please see my edit.
153
thank you