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.
  • 171,639
  • 30
  • 264
  • 288
  • 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
  • 36,322
  • 27
  • 84
  • 93
MKR
  • 19,739
  • 4
  • 23
  • 33
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.LocalApp‌​licationData);
Directory.Delete(directory, true);
Ayaz
  • 2,111
  • 4
  • 13
  • 16