我需要通过运行控制台应用程序来删除位于文件夹中的一些文件。但是它似乎不起作用,我不确定我在这里做错了什么?
这是我正在使用的代码:
string[] filePaths = Directory.GetFiles(@"% USERPROFILE %\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\");
foreach (string filePath in filePaths)
File.Delete(filePath);
运行应用程序时,这是我收到的错误:
Could not find a part of the path 'C:\Users\PC\source\repos\InstallUpdate\InstallUpdate\bin\Debug\netcoreapp3.1\% USERPROFILE %\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup'.'
似乎它正在使用netcoreapp3.1
作为默认位置?
谢谢
尝试使用 Environment.ExpandEnvironmentVariables
string path = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\");
var filesToDelete = Directory.GetFiles(path);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句