Reputation: 1
Hello stackoverflow community, I want to know how I would be able to do this code: Directory.Delete(@"C:\NAME\AppData\Local", true);
But where it says "NAME" I want to get the username of the computer, is this possible? Thanks.
Upvotes: 0
Views: 152
Reputation: 20095
I hope you are looking for a way to replace "NAME" with current user logged on that computer. If so then you can use Environment.UserName
. Environment.UserName
will return you the user on the current thread.
Upvotes: 1
Reputation: 2121
Try this.
Directory.Delete(string.Format(@"C:\{0}\AppData\Local",Environment.UserName), true);
As per Alex comment, if you want to delete "C:\USERS\NAME\AppData\Local" then use this code.
var directory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
Directory.Delete(directory, true);
Upvotes: 0
Reputation: 1939
You can use, Getting the computer name in windows
and
string directory = "C:\"+username+"\AppData\Local";
Directory.Delete(@directory, true);
Upvotes: 0