0

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?

  • [Wildcard characters are not supported](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.delete?view=net-5.0), use Directory.EnumerateFiles(). – Hans Passant Jun 03 '21 at 20:01
  • @HansPassant is right: [other answers](https://stackoverflow.com/a/8807273/4166522) show how to do what he says. – Rich N Jun 03 '21 at 20:03

0 Answers0