我需要创建一个条件,将选定的多个文件从一个文件夹移动/复制到另一个文件夹我使用openfile对话框浏览文件并将其设置为多选,然后我为目录和文件名创建了一个标签现在使用m只复制一个选定的文件,我需要一次保存所有选定的文件。
此代码用于插入附件
Dim a As OpenFileDialog = New OpenFileDialog
a.Multiselect = True
If a.ShowDialog() = Windows.Forms.DialogResult.OK Then
removeatt.Show()
removeatt.Text = "Remove Attachment"
fpath.Text = a.FileName
fname.Text = System.IO.Path.GetFileName(a.FileName)
Dim file As String
file = fpath.Text.ToString
Label7.Text = file
If fpath.Text = "-" Then
removeatt.Hide()
Else
removeatt.Show()
End If
End If
这是保存/复制部分
Dim dir As String
Dim dir2 As String
dir = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
dir2 = Path.Combine(dir, "Site images and attachments/" & Label33.Text & "/")
If Not Directory.Exists(dir2) Then
Directory.CreateDirectory(dir2)
End If
If fpath.Text = "-" Then
Else
My.Computer.FileSystem.CopyFile(fpath.text, dir2 + fname.Text, Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing)
End If
再次,我需要它来保存所有选定的文件
感谢
答案 0 :(得分:0)
在这段代码中,我将向您展示如何获取所有文件路径。 对于保存部分,您必须拆分生成的文本并执行相同的操作。
Dim a As OpenFileDialog = New OpenFileDialog
Dim fname As String
a.Multiselect = True
If a.ShowDialog() = Windows.Forms.DialogResult.OK Then
removeatt.Show()
removeatt.Text = "Remove Attachment"
For Each fname In a.FileNames
fpath.Text = fpath.Text + IIf(fpath.Text.Trim <> "", "-", "") + fname
Next
Label7.Text = fpath.Text
End If
答案 1 :(得分:0)
对于保存部分,您可以使用“ - ”字符拆分fpath.text并将结果放入字符串数组中,如下所示:
dim filenames as string() <--- this is how to define string array
filenames = f.path.text.split("-")
for each file as string in filenames
<----- save file commands
next