如何使用VB.net从加密驱动器复制文件?

时间:2015-02-23 15:58:08

标签: vb.net encryption file-io filesystems

我已经编写了一小段代码(见下文),用于将USB驱动器上的文件和文件夹备份到本地磁盘。该程序工作正常,但在使用BitLocker加密闪存驱动器后。我收到以下错误

enter image description here

我还应该注意,可以通过Windows资源管理器访问该驱动器。提前谢谢。

Imports System
Imports System.IO
Module Module1

    Sub Main()
        If My.Computer.Name = UCase("My-Toshiba") Then
            CopyDirectory(Directory.GetCurrentDirectory(), "C:\Users\me\Documents\USB_Backup")
        End If
    End Sub
    Private Sub CopyDirectory(ByVal sourcePath As String, ByVal destinationPath As String)
        Dim sourceDirectoryInfo As New System.IO.DirectoryInfo(sourcePath)

        If Not System.IO.Directory.Exists(destinationPath) Then ' If the destination folder don't exist then create it
            System.IO.Directory.CreateDirectory(destinationPath)
        End If

        Dim fileSystemInfo As System.IO.FileSystemInfo
        For Each fileSystemInfo In sourceDirectoryInfo.GetFileSystemInfos
            Dim destinationFileName As String = System.IO.Path.Combine(destinationPath, fileSystemInfo.Name)

            If TypeOf fileSystemInfo Is System.IO.FileInfo Then 'check whether its a file or a folder and take action accordingly
                If Not System.IO.File.Exists(destinationFileName) Then
                    System.IO.File.Copy(fileSystemInfo.FullName, destinationFileName, True)
                Else
                    Dim destFileInfo As New FileInfo(destinationFileName)
                    If fileSystemInfo.LastWriteTime > destFileInfo.LastWriteTime Then
                        System.IO.File.Copy(fileSystemInfo.FullName, destinationFileName, True)
                    End If
                End If
            Else
                If Not System.IO.File.Exists(destinationFileName) Then
                    CopyDirectory(fileSystemInfo.FullName, destinationFileName) ' Recursively call the mothod to copy all the nested folders
                Else
                    Dim destFileInfo As New FileInfo(destinationFileName)
                    If fileSystemInfo.LastWriteTime > destFileInfo.LastWriteTime Then
                        CopyDirectory(fileSystemInfo.FullName, destinationFileName)
                    End If
                End If
            End If
        Next

    End Sub
End Module

0 个答案:

没有答案