System.ArgumentException: 'Illegal characters in path. when deleting a file using C#

61 Views Asked by At

I'm creating a small program in C# to delete the files that start with the word "python".exe in this directory

C:\Users\<username>\AppData\Local\Microsoft\WindowsApps\

I used this code

string filetoDelete = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\\AppData\\Local\\Microsoft\\WindowsApps" + @"\\*python*.exe";
File.Delete(filetoDelete);

when I run the program it gives me this error message

System.ArgumentException: 'Illegal characters in path.'

and the red X is marked next to File.Delete(filetoDelete); how do I fix this?

0

There are 0 best solutions below