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.
Asked
Active
Viewed 43 times
0

Alex K.
- 171,639
- 30
- 264
- 288

John Johnson
- 1
- 1
-
If you mean `C:\USERS\NAME\AppData\Local` then `Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)` – Alex K. Jun 17 '17 at 16:41
3 Answers
1
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.
0
You can use, Getting the computer name in windows
and
string directory = "C:\"+username+"\AppData\Local";
Directory.Delete(@directory, true);

ahmeticat
- 1,899
- 1
- 13
- 28
0
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);

Ayaz
- 2,111
- 4
- 13
- 16