从文件夹中删除文件似乎不起作用?

Removing files from folder does not seem to be working?

我需要通过 运行 控制台应用程序删除文件夹中的一些文件。但是它似乎没有用,我不确定我在这里做错了什么?

这是我使用的代码:

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

https://docs.microsoft.com/en-us/dotnet/api/system.environment.expandenvironmentvariables?redirectedfrom=MSDN&view=net-5.0#System_Environment_ExpandEnvironmentVariables_System_String_