PC Review


Reply
Thread Tools Rate Thread

Delete Users Files

 
 
Jeff
Guest
Posts: n/a
 
      4th Dec 2008
I'm trying to delete all the files in a users directory. I know there are
some that can't be deleted, that's ok. What I'm trying to do, is delete any
files that 'johnboy' might have saved to his folder when he was logged on
(Vista).
Here is my code:

private void DeleteFiles()
{
string dir = @"C:\users\johnboy\";
try
{
if (System.IO.Directory.Exists(dir))
{
string[] dirs = System.IO.Directory.GetDirectories(dir,
"*.*", System.IO.SearchOption.AllDirectories);
string[] files = System.IO.Directory.GetFiles(dir,
"*.*", System.IO.SearchOption.AllDirectories);
foreach (string file in files)
{
try
{
System.IO.File.Delete(file);
}
catch { }
}
foreach (string name in dirs)
{
try
{
System.IO.Directory.Delete(name, true);
}
catch { }
}
}
}
catch (Exception ex)
{
string err = ex.Message;
}
}

I get the exception: "Unable to delete files on the desktop: Access to the
path 'C:\users\johnboy\Desktop\' is denied". Problem is that it breaks out
of the foreach statement and quits deleting files. I really just want to
clean up as much as I can, any help is appreciated.
 
Reply With Quote
 
 
 
 
Jeff Johnson
Guest
Posts: n/a
 
      5th Dec 2008
"Jeff" <(E-Mail Removed)> wrote in message
news:6F8E9382-A0A6-417F-A6E4-(E-Mail Removed)...

> I'm trying to delete all the files in a users directory. I know there are
> some that can't be deleted, that's ok. What I'm trying to do, is delete
> any
> files that 'johnboy' might have saved to his folder when he was logged on
> (Vista).


Other than the fact that you might be running this from a form, this
question has nothing to do with Windows Forms. You might have better luck
asking in a C# or .NET Framework group.


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Files for Non-Existent Users =?Utf-8?B?SmVmZg==?= Windows XP Configuration 3 22nd Oct 2007 02:56 PM
Delete ALL Temp I-net Files (All Users) Dale Windows XP General 1 16th Mar 2007 03:39 AM
delete IE temp files for all users anonymous Windows XP General 1 3rd Nov 2004 07:37 AM
users unable to delete/destroy files/folders in /users/%username%directory Rafael Block Microsoft Windows 2000 Networking 4 8th Nov 2003 09:19 AM
users unable to delete/destroy files/folders in /users/%username%directory Rafael Block Microsoft Windows 2000 Active Directory 4 8th Nov 2003 09:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:12 PM.