Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
远程删除文件夹vb.net 2017中的文件_Vb.net_Networking_Lan - Fatal编程技术网

远程删除文件夹vb.net 2017中的文件

远程删除文件夹vb.net 2017中的文件,vb.net,networking,lan,Vb.net,Networking,Lan,我有一些代码可以通过LAN网络删除文件夹中的所有文件。 我不知道为什么,但它从未捕捉到异常以显示错误它将崩溃我已经测试了从网络脱机删除功能,该部分代码工作正常(可以在网络上测试,直到明天返回工作)。有人知道我在这方面出了什么问题吗?还有没有更好的方法来编写代码,因为它让人感觉太草率了,好像它执行的简单函数太多了。 这意味着要清除windows中默认临时目录的任何文件和子文件夹的3个临时文件夹上的时间文件。首先,它会选中一个文本框,查看是否输入了工作站名称,如果没有,它会选中下一个文本框,查看IP

我有一些代码可以通过LAN网络删除文件夹中的所有文件。 我不知道为什么,但它从未捕捉到异常以显示错误它将崩溃我已经测试了从网络脱机删除功能,该部分代码工作正常(可以在网络上测试,直到明天返回工作)。有人知道我在这方面出了什么问题吗?还有没有更好的方法来编写代码,因为它让人感觉太草率了,好像它执行的简单函数太多了。 这意味着要清除windows中默认临时目录的任何文件和子文件夹的3个临时文件夹上的时间文件。首先,它会选中一个文本框,查看是否输入了工作站名称,如果没有,它会选中下一个文本框,查看IP my code如下:

 Private Sub TempCleanButton_Click(sender As Object, e As EventArgs) Handles TempCleanButton.Click
    If txtWS.Text = "" Then
        ToolStripStatusLabel1.Text = "Deleting Temp Files Please Wait..."
        ' loop through each file in the target directory
        For Each filePath As String In Directory.GetFiles("\\" & txtIP.Text & "\C$\Windows\Temp")
            Try

                'Delete the file if possible...otherwise skip it
                File.Delete(filePath)
            Catch ex As Exception
                MsgBox("Unable to Delete: " & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical)
            End Try

        Next
        ' loop through each file in the target directory
        For Each SubFolderPath As String In Directory.GetDirectories("\\" & txtIP.Text & "\C$\Windows\Temp")

            ' delete the sub-folder if possible...otherwise skip it
            Try
                Directory.Delete(SubFolderPath)
            Catch ex As Exception
                MsgBox("Unable to Delete: " & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical)
            End Try

        Next

        ' loop through each file in the target directory
        For Each filePath As String In Directory.GetFiles("\\" & txtIP.Text & "\C$\Windows\Tmp")
            Try

                'Delete the file if possible...otherwise skip it
                File.Delete(filePath)
            Catch ex As Exception
                MsgBox("Unable to Delete: " & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical)
            End Try

        Next
        ' loop through each file in the target directory
        For Each SubFolderPath As String In Directory.GetDirectories("\\" & txtIP.Text & "\C$\Windows\Tmp")

            ' delete the sub-folder if possible...otherwise skip it
            Try
                Directory.Delete(SubFolderPath)
            Catch ex As Exception
                MsgBox("Unable to Delete: " & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical)
            End Try

        Next

        ' loop through each file in the target directory
        For Each filePath As String In Directory.GetFiles("\\" & txtIP.Text & "C:\Users\Environment.UserName\AppData\Local\Temp")
            Try

                'Delete the file if possible...otherwise skip it
                File.Delete(filePath)
            Catch ex As Exception
                MsgBox("Unable to Delete: " & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical)
            End Try

        Next
        ' loop through each file in the target directory
        For Each SubFolderPath As String In Directory.GetDirectories("\\" & txtIP.Text & "C:\Users\Environment.UserName\AppData\Local\Temp")

            ' delete the sub-folder if possible...otherwise skip it
            Try
                Directory.Delete(SubFolderPath)
            Catch ex As Exception
                MsgBox("Unable to Delete: " & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical)
            End Try
        Next
    Else
        ToolStripStatusLabel1.Text = "Deleting Temp Files Please Wait..."
        ' loop through each file in the target directory
        For Each filePath As String In Directory.GetFiles("\\" & txtWS.Text & "\C$\Windows\Temp")
            Try

                'Delete the file if possible...otherwise skip it
                File.Delete(filePath)
            Catch ex As Exception
                MsgBox("Unable to Delete: " & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical)
            End Try

        Next
        ' loop through each file in the target directory
        For Each SubFolderPath As String In Directory.GetDirectories("\\" & txtWS.Text & "\C$\Windows\Temp")

            ' delete the sub-folder if possible...otherwise skip it
            Try
                Directory.Delete(SubFolderPath)
            Catch ex As Exception
                MsgBox("Unable to Delete: " & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical)
            End Try

        Next

        ' loop through each file in the target directory
        For Each filePath As String In Directory.GetFiles("\\" & txtWS.Text & "\C$\Windows\Tmp")
            Try

                'Delete the file if possible...otherwise skip it
                File.Delete(filePath)
            Catch ex As Exception
                MsgBox("Unable to Delete: " & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical)
            End Try

        Next
        ' loop through each file in the target directory
        For Each SubFolderPath As String In Directory.GetDirectories("\\" & txtWS.Text & "\C$\Windows\Tmp")

            ' delete the sub-folder if possible...otherwise skip it
            Try
                Directory.Delete(SubFolderPath)
            Catch ex As Exception
                MsgBox("Unable to Delete: " & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical)
            End Try

        Next

        ' loop through each file in the target directory
        For Each filePath As String In Directory.GetFiles("\\" & txtWS.Text & "C:\Users\Environment.UserName\AppData\Local\Temp")
            Try

                'Delete the file if possible...otherwise skip it
                File.Delete(filePath)
            Catch ex As Exception
                MsgBox("Unable to Delete: " & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical)
            End Try

        Next
        ' loop through each file in the target directory
        For Each SubFolderPath As String In Directory.GetDirectories("\\" & txtWS.Text & "C:\Users\Environment.UserName\AppData\Local\Temp")

            ' delete the sub-folder if possible...otherwise skip it
            Try
                Directory.Delete(SubFolderPath)
            Catch ex As Exception
                MsgBox("Unable to Delete: " & vbCrLf & "Error: " & ex.Message, MsgBoxStyle.Critical)
            End Try
        Next
    End If
End Sub

这个\\“&txtIP.Text&”C:\Users\Environment.UserName\AppData\Local\Temp肯定不是有效的pathwell我明天才能通过网络进行测试,但是使用Environment.UserName变量应该可以工作,所以我假设它需要是变量,因为每个人都用自己的名字登录。为什么您认为它不起作用?因为A)您的路径将导致例如:
\\1.2.3.4C:\Users\Environment.UserName\AppData\Local\Temp
和B)
Environment.UserName
返回此计算机的登录用户,但您拥有的是一个字符串,因此文本“Environment.UserName”文本将始终位于字符串中。要正确执行此操作,您必须在IP后添加斜杠,将
C:
更改为
C$
,最后连接
环境。换行符
,而不是直接将其放入字符串中。-它应该是什么样子:
“\\”&txtIP.Text&“\C$\Users\”&Environment.UserName&“\AppData\Local\Temp
.omg当然,这是一个多么愚蠢的错误,我用其他路径纠正了它。我简直不敢相信我没有注意到我整天都在制作这个应用程序,我想我需要休息一下谢谢你指出这一点!今天早些时候,当我的文件正在使用且无法删除时,它捕获了异常并提供了一条错误消息,然后我更改了一些代码,现在它不工作了,我打赌这是因为上面所说的一些愚蠢的事情,我要睡一觉,重新审视一下,谢谢你的输入