You know that in linux it's easy but I can't just understand how to do it in C# on Windows. I want to delete all files matching the wildcard f*.txt
. How do I go about going that?
Click the first file or folder, and then press and hold the Ctrl key. While holding Ctrl , click each of the other files or folders you want to select.
Python Delete Files Wildcard To remove files by matching a wildcard pattern such as '*. dat' , first obtain a list of all file paths that match it using glob. glob(pattern) . Then iterate over each of the filenames in the list and remove the file individually using os.
You can delete multiple files or folders by holding down the Ctrl key and clicking each file or folder before pressing Delete . You can hold down the Shift key while pressing the Delete key to prevent files from going to the Recycle Bin when deleted.
You can use the DirectoryInfo.EnumerateFiles
function:
var dir = new DirectoryInfo(directoryPath); foreach (var file in dir.EnumerateFiles("f*.txt")) { file.Delete(); }
(Of course, you'll probably want to add error handling.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With