I want create directory (if not exist) in path AppData/Roaming/test. But my code doesn't work, I dont know why. Can you help me?
string path;
path = @"%AppData%\Roaming\test\";
path = Environment.ExpandEnvironmentVariables(path);
Console.WriteLine(path);
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
This code doen't create dir.
%AppData% is a SpecialFolder.
change your code from:
path = @"%AppData%\Roaming\test\";
to:
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var path = Path.Combine(appDataPath, @"test\");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With