我有一个名为test的文件夹,它的根目录下有子文件夹: A、B和C。我正在尝试将一个文件复制到这三个文件夹中。
不确定I出现错误的原因:
目标文件"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发布于 2013-04-11 04:51:49
您正在向CopyTo传递一个目录名。
该方法需要文件名,而不是目录名。
因此收到了异常。
如果我很好地理解您的代码,您需要将该行更改为
Dim destFile = Path.Combine(subfolder.FullName, OPUSINI.Name))
OPUSINI.CopyTo(destFile, True)此外,在这里使用DirectoryInfo对象也不是真正必要的。
简单的Directory类可以用更少的开销做同样的事情
https://stackoverflow.com/questions/15934928
复制相似问题