下午好一切,的Visual Studio 2013 - 移动文件到其他路径
我试图创建此代码,让我从我进入TextBox1.Text在目录中创建一个新的文件夹,然后打开一个对话框,然后选择一个PDF,然后将文件路径放入TextBox2(TextBox3中的单独PDF也是如此)。
An unhandled exception of type 'System.IO.IOException' occurred in Microsoft.VisualBasic.dll
Additional information: Could not complete operation since a directory already exists in this path '\\ANVILSRV\Public\Completed Works Orders\98789'.
-
这是试图完成操作时,我得到的错误,它创建的文件夹,不会移动任何文件。
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim txt As String
txt = TextBox1.Text
If My.Computer.FileSystem.DirectoryExists("\\ANVILSRV\Public\Completed Works Orders\" & txt & "") Then
MsgBox("Could not create the folder " & txt & " because it already exists.")
Else
My.Computer.FileSystem.CreateDirectory("\\ANVILSRV\Public\Completed Works Orders\" & txt & "")
My.Computer.FileSystem.MoveFile(TextBox2.Text, ("\\ANVILSRV\Public\Completed Works Orders\" & txt & ""), True)
My.Computer.FileSystem.MoveFile(TextBox3.Text, ("\\ANVILSRV\Public\Completed Works Orders\" & txt & ""), True)
End If
End Sub
任何意见或帮助,非常感谢。
谢谢,
斯蒂芬
我觉得TextBox1中和2将需要完全合格的路径。如果目录已经存在,奇怪的“附加信息”消息与CreateDirectory()不会引发错误。检查存在可能是很好的做法,但不是必需的。文档声明IOException错误与权限有关,而不是存在。如果from路径不完全限定会导致IOException。 – rheitzman
我想我看到了问题 - from和to应该是完全限定的'filenames'。 To不是一个文件夹,而是一个完全合格的路径。 – rheitzman