Directory.GetFiles - SearchOption.AllDirectories不提供子文件夹中的文件(vb)

时间:2015-08-10 14:48:06

标签: vb.net getfiles

Directory.GetFiles - SearchOption.AllDirectories不提供位于子文件夹中的文件。我正在尝试将al .jpg文件从usb复制到计算机,但是当文件位于子文件夹中时,它不会复制它们。

Private Sub ButtonStart_Click(sender As Object, e As EventArgs) Handles ButtonStart.Click
    Dim sourceDir As String = ComboBoxUsbSelect.Text
    Dim backupDir As String = FileDestination

    Try

        Dim picList As String() = Directory.GetFiles(sourceDir, "*.jpg", SearchOption.AllDirectories)

        ' Copy picture files. 
        For Each f As String In picList
            'Remove path from the file name. 
            Dim fName As String = f.Substring(sourceDir.Length)

            ' Use the Path.Combine method to safely append the file name to the path. 
            ' Will overwrite if the destination file already exists.
            If delete = False Then
                File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName), True)
            Else
                File.Move(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName))
            End If
        Next
    Catch dirNotFound As DirectoryNotFoundException
        Console.WriteLine(dirNotFound.Message)
    End Try
    MessageBox.Show("Done!")
End Sub

0 个答案:

没有答案
相关问题