简体   繁体   中英

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

You should use Environment.ExpandEnvironmentVariables before using windows variable:

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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