0

ルートにサブフォルダー A、B、および C がある test というフォルダーがあります。これらの 3 つのフォルダーにファイルをコピーしようとしています。

エラーが発生する理由がわかりません:

ターゲット ファイル「c:\test\A」は、ファイルではなくディレクトリです。助けてください。

 Dim OPUSINI As New FileInfo("C:\Program Files (x86)\OPUS_4.5\OPUS32.INI")
    'Where is will be going
    'Dim Win7DestLocation As String = "C:\Users"
    Dim Win7DestLocation As String = "C:\test"
    Dim WinXPDestLocation As String = "C:\Documents and Settings"
    'Get a list of all the Subfolders within the Destination location
    Dim Win7Destdir As New DirectoryInfo(Win7DestLocation)
    Dim WinXPDestdir As New DirectoryInfo(WinXPDestLocation)
    'Checks if Destination Exists for Windows 7
    Dim Win7CheckExistDestLocation As New IO.DirectoryInfo(Win7DestLocation)
    'Checks if Destination Exists for Windows XP
    Dim WinXPCheckExistDestLocation As New IO.DirectoryInfo(WinXPDestLocation)
    If Win7CheckExistDestLocation.Exists Then
        Try
            For Each subfolder As DirectoryInfo In Win7Destdir.GetDirectories


                OPUSINI.CopyTo(subfolder.FullName, True)
            Next
        Catch ex As Exception
            MessageBox.Show("Unable to backup Pump data files." + ex.ToString, "Backup Error:", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
4

1 に答える 1

1

ディレクトリ名をCopyToに渡しています。
そのメソッドは、ディレクトリ名ではなくファイル名を必要とします。
したがって、例外を受け取りました。

あなたのコードをよく理解している場合は、その行を次のように変更する必要があります

Dim destFile = Path.Combine(subfolder.FullName, OPUSINI.Name))
OPUSINI.CopyTo(destFile, True)

また、ここでは DirectoryInfo オブジェクトを使用する必要はありません。
単純なDirectoryクラスは、より少ないオーバーヘッドで同じことを行うことができます

于 2013-04-10T20:51:48.817 に答える