0

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.

Alex K.
  • 165,803
  • 30
  • 257
  • 277
  • If you mean `C:\USERS\NAME\AppData\Local` then `Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)` – Alex K. Jun 17 '17 at 16:41

3 Answers3

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.

Paul Roub
  • 35,848
  • 27
  • 79
  • 88
MKR
  • 19,150
  • 4
  • 21
  • 32
0

You can use, Getting the computer name in windows

and

string directory = "C:\"+username+"\AppData\Local"; Directory.Delete(@directory, true);

ahmeticat
  • 1,769
  • 1
  • 11
  • 26
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.LocalApp‌​licationData);
Directory.Delete(directory, true);
Ayaz
  • 1,941
  • 2
  • 12
  • 14