请帮助,我有一个错误:
File.Copy(@"%USERPROFILE%\AppData\Local\Google\Chrome\UserData\Default\Bookmarks", @"%userprofile%\Music\Bookmarks", true);
C#看不到此路径:C
答案 0 :(得分:6)
在使用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);