【发布时间】:2016-04-24 22:03:50
【问题描述】:
我正在寻找一些指导,以使某个函数适用于我正在开发的程序。
我坚持的功能是从远程计算机上的多个目录中删除该计算机上所有用户配置文件的所有文件。
目前,在添加 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
【问题讨论】:
标签: vb.net delete-file temp multiple-users