简体   繁体   English

C#环境变量问题

[英]Trouble with environment variables in C#

Please help, I have an error:请帮忙,我有一个错误:

File.Copy(@"%USERPROFILE%\AppData\Local\Google\Chrome\UserData\Default\Bookmarks", @"%userprofile%\Music\Bookmarks", true);

C# can't see this path :C C# 看不到这条路径:C

You should use Environment.ExpandEnvironmentVariables before using windows variable:在使用 windows 变量之前,您应该使用Environment.ExpandEnvironmentVariables

var path1 = @"%USERPROFILE%\AppData\Local\Google\Chrome\UserData\Default\Bookmarks";
var filePath1 = Environment.ExpandEnvironmentVariables(path1);

var path2 = @"%userprofile%\Music\Bookmarks";
var filePath2 = Environment.ExpandEnvironmentVariables(path2);

File.Copy(filePath1, filePath2, true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM