I was wondering what would be a good way to scan a directory that has characters you are not sure of.
For example, I want to scan
C:\Program\Version2.*\Files
Meaning
C:\Program
Version2.*
could be anything like Version2.33
, Version2.1
, etc. Files
in itI know that I could do something like foreach (directory) if contains("Version2.")
, but I was wondering if there was a better way of doing so.
The Directory Path field supports standard common wildcard asterisk (*) or the question mark (?) for matching directory names.
To locate a specific item when you can't remember exactly how it is spelled, try using a wildcard character in a query. Wildcards are special characters that can stand in for unknown characters in a text value and are handy for locating multiple items with similar, but not identical data.
Finding Files Recursively in Linux The find command does not need flags to search the files recursively in the current directory. You only need to define the main directory and the file name using the –name option. This command will search the file within the main directory and all subdirectories.
Rather than entering each file by name, using wildcards in the Source path allows you to collect all files of a certain type within one or more directories, or many files from many directories.
Directory.EnumerateDirectories accepts search pattern. So enumerate parent that has wildcard and than enumerate the rest:
var directories =
Directory.EnumerateDirectories(@"C:\Program\", "Version2.*")
.SelectMany(parent => Directory.EnumerateDirectories(parent,"Files"))
Note: if path can contain wildcards on any level - simply normalize path and split by "\", than collect folders level by level.
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