From solution 2 and 3, you already know that you should really need
File.Move
. I only have to add that even of the source and destination files are in different directories but in the same disk volume, it's not physically moving of the whole file — the file system is not that stupid. It's still closer to renaming, by functionality.
Now, remaining thing is using the wildcard. No one explained it; and the idea of using Regex (Solution 1) is irrelevant.
Really, the wildcards can come with
System.IO.Directory.GetFiles(string, string, SearchOption)
, in a second parameter,
searchPattern
:
Directory.GetFiles Method (String, String, SearchOption) (System.IO)[
^].
However, it works not exactly as most people would reasonably expect. I would even call it a flaw or a bug in the system. Please see my past answer explaining that:
Directory.Get.Files search pattern problem[
^].
—SA