【发布时间】:2017-07-23 20:28:21
【问题描述】:
我在使用 FileSystemObject.CopyFile 时遇到问题。从我读过的论坛中,我认为我使用正确,但我仍然收到以下编译器错误:
ArgumentException 未处理:值不在预期范围内
代码如下:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim fso As New Scripting.FileSystemObject
Dim testfolderchk
testfolderchk = Dir("C:\Test\")
Dim inforeader As System.IO.FileInfo
Dim filedestinationcheck = Dir("C:\Test2\")
If testfolderchk <> "" Then
If Microsoft.VisualBasic.Left(testfolderchk, 4) = "test" Then
inforeader = My.Computer.FileSystem.GetFileInfo("C:\Test" & testfolderchk)
filetime = (inforeader.LastWriteTime)
If testfolderchk = filedestinationcheck Then GoTo skipfile
If testfolderchk = filedestinationcheck2 Then GoTo skipfile
Else : GoTo skipfile
End If
End If
fso.CopyFile(testfolderchk, filedestinationcheck, True)
【问题讨论】:
-
System.IO命名空间有各种文件相关的方法,这些方法比FileSystemObject更适合 NET 代码。 -
建议?有人吗?
-
Suggestions?是的,不要使用 FSO 也不要使用GoTo。只需稍加研究,您就可以在这里找到数百个文件复制小程序 -
正如@Plutonix 所建议的那样。查看
System.IO命名空间。这有Directory、DirectoryInfo、File、FileInfo,这应该是您获取信息和复制文件所需的全部内容。不要使用FileSystemObject。 -
我也不确定你在这里做什么
("C:\Test" & testfolderchk)。那不是("C:\TestC:\Test\")吗?由于testfolderchk已被分配“C:\Test”
标签: vb.net filesystemobject file-copying