My question is how to try to interpret a String so that I can use it in the File class as a path, but with wildcards in the same way as in Bash I can do this:
rm -rf /tmp/*/folder1/*
I want to know how to implement a comfortable way to be able to do it. I have seen that I have to use Regex for it, but I am still not clear how to use it.
I want to use it this way:
string path = "/tmp/*/folder1/*";
File.Delete (path);
I hope you can help me.
You don't need regex to use a string with special characters, you just need to add the @ character to generate a verbatim string which requires no escape sequence
In the case that
File.Delete(string ruta);
you must pass the name of the file to be deleted with its respective path, so the wildcards will not be used in this case, you will need to use:To recursively go through the directories in the specified path and extract the files with their path that interest you.
According to the OP's comment: to delete files from that path:
All folders named folder1 within the given root path will be found and their files deleted depending on the pattern set in
EnumerateFiles
Here is the documentation of how File.Delete(string path) works
Cheers