我有一个名为 FILELISTS 的表
Table Name - Filelists
Field - FileNames
数据价值
- 文件1.txt
- 文件2.csv
- 文件 3*.csv
我正在努力编写代码,如上所述,如果它具有需要从源复制到目标的文件名(如 file1.txt 和 file2.txt)。如果文件名是模式(如 File3*.csv),则将与此模式匹配的所有文件从源复制到目标。
我正在使用数据阅读器在 Vb.net 中枚举上面的行。
我有一个名为 FILELISTS 的表
Table Name - Filelists
Field - FileNames
我正在努力编写代码,如上所述,如果它具有需要从源复制到目标的文件名(如 file1.txt 和 file2.txt)。如果文件名是模式(如 File3*.csv),则将与此模式匹配的所有文件从源复制到目标。
我正在使用数据阅读器在 Vb.net 中枚举上面的行。
您可以使用Directory.EnumerateFiles
and 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
DirectoryInfo,FileInfo - 在我点击帖子之前,您删除了您的其他问题......但这适用于.net framework 2.0,就像您问的那样
Option Strict On
Imports sO = System.IO.SearchOption
Imports dI = System.IO.DirectoryInfo
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For Each F In (New dI("C:\")).GetFiles("*.*", sO.TopDirectoryOnly)
MsgBox(F.FullName)
'Do your copy here
Next
End Sub
End Class