我正在寻找一些关于让一个函数为我正在开发的程序工作的指导。
我坚持的功能旨在从远程计算机上的多个目录中删除该计算机上所有用户配置文件的所有文件。
目前,我正在尝试在添加 file.delete() 之前将目录和子目录中的所有文件输出到我的文本框。
所有“项目”都显示为一个字母字符,因为它将文件路径中的每个字母分隔成一个单独的项目(可能是我做的方式For..Each
)。
我知道我犯了多个新手错误,因为我对 VB.net 还很陌生,并且仍处于学习阶段,但我正在寻找一些指导。
我一直在寻找并将碎片拼凑起来以使其正常工作,但已经碰壁了,感谢您的帮助!
当前代码:
Private Sub Deltemp_Click(sender As Object, e As EventArgs) Handles Deltemp.Click
If Compname2.Text = "" Then
MessageBox.Show("You didn't enter anything in the Computername field, please enter something then try again.")
GoTo statementend
End If
Try
If My.Computer.Network.Ping(Compname2.Text, 1000) Then
PSoutput.Text = ""
Else
PSoutput.Text &= Compname2.Text + " is not connected to our network currently."
GoTo statementend
End If
PSoutput.Text = ""
Dim userpath As String = "\\" + Compname2.Text + "\c$\users\"
Dim tempu(7) As String
tempu(0) = "\AppData\Local\Temp\"
tempu(1) = "\AppData\Local\Microsoft\Windows\Temporary Internet Files\"
tempu(2) = "\AppData\Local\Microsoft\Credentials"
tempu(3) = "\AppData\Local\Temporary Internet Files\"
tempu(4) = "\AppData\Roaming\Microsoft\Credentials"
tempu(5) = "\AppData\Roaming\SUN"
tempu(6) = "\AppData\Local\Apps\2.0"
Dim fsd As Object
fsd = FileIO.FileSystem.GetDirectories(userpath)
For Each user In fsd
Try
Dim filepaths = FileIO.SpecialDirectories.AllUsersApplicationData()
If user Like "*Default*" Or user Like "*.NET*" Or user Like "*All Users" Or user Like "*Public" Then
PSoutput.Text &= ""
Else
Dim Fullpath = user + tempu(7)
For Each item In Fullpath
FileIO.FileSystem.GetFiles(Fullpath)
PSoutput.Text &= item.ToString + " was found" & Environment.NewLine
Next
End If
Catch ex As Exception
PSoutput.Text &= "A file was skipped for being in use or an exception occured" & Environment.NewLine
End Try
Next
Catch
MessageBox.Show("The machine/ip entered doesn't exist on our network or is an invalid entry")
End Try
statementend:
End Sub