我正在尝试将目录中的文件复制到新文件夹中。该脚本仅处理一种文件类型,但我需要搜索6种类型。我以为可以像使用Regex一样使用竖线(“ |”),但这没用。然后我尝试使用数组,但没有运气。
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnMove.Click
Dim sourceDir As String
sourceDir = txtMovePath.Text
Dim foundFile As Object = Nothing
Dim graphicsFldr As String
graphicsFldr = sourceDir + "\Graphics\"
For Each foundFile In My.Computer.FileSystem.GetFiles(sourceDir, _
Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, _
"*.cgm|*.eps|*.svg|*.wmf|*.jpg|*.png|*.iso")
My.Computer.FileSystem.CopyFile(foundFile, graphicsFldr & My.Computer.FileSystem.GetName(foundFile))
Next
End Sub
End Class
Module mainModule
Sub Main()
Form1.Show()
End Sub
答案 0 :(得分:1)
使用此
Dim arr = {"*cgm","*.eps","*.svg","*.wmf","*.jpg","*.png","*.iso"}
For Each foundFile In My.Computer.FileSystem.GetFiles(sourceDir, _
Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, arr)
My.Computer.FileSystem.CopyFile(foundFile, graphicsFldr & My.Computer.FileSystem.GetName(foundFile))
Next