Directory.EnumerateFiles
とを使用できますFile.Copy
。たとえば、次のようになります。
var filePatterns = database.GetFileNamePattern(); // your method that returns the list of files
// assuming you've stored the source- and dest.-directories in the app-settings
string sourceFolder = Properties.Settings.Default.SourceFolder;
string destFolder = Properties.Settings.Default.DestinationFolder;
foreach (string pattern in filePatterns)
{
var files = Directory.EnumerateFiles(
sourceFolder,
pattern,
SearchOption.TopDirectoryOnly);
foreach (string file in files)
{
File.Copy(file, Path.Combine(destFolder, Path.GetFileName(file)), true);
}
}
編集:申し訳ありませんが、ここではVB.NETバージョン:
' your method that returns the list of files:
Dim filePatterns = database.GetFileNamePattern()
' assuming you've stored the source- and dest.-directories in the app-settings
Dim sourceFolder As String = My.Settings.SourceFolder
Dim destFolder As String = My.Settings.DestinationFolder
For Each pattern As String In filePatterns
Dim files = Directory.EnumerateFiles(sourceFolder, pattern, SearchOption.TopDirectoryOnly)
For Each file As String In files
IO.File.Copy(file, IO.Path.Combine(destFolder, IO.Path.GetFileName(file)), True)
Next
Next