2015-09-06 103 views
0
中的文件

有什么错误使用此代码? 我写了这个程序删除一些文件,而无需将其发送给我每次运行程序时回收站 并尝试删除文件(C)根 代码菜单中显示的错误告诉我,文件无法删除无法删除C:

Public Class Form1 
Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click 
    Try 
     Dim x As String 
     x = txtfolder.Text 
     If txtfolder.Text = "" Then 
      MessageBox.Show("Write An Address Then Click ^Goto^", _ 
      "Super Deleter", MessageBoxButtons.OK, _ 
      MessageBoxIcon.Information) 

     ElseIf MessageBox.Show("Are you sure You want to Delete File(s)?", _ 
       "Super Deleter", MessageBoxButtons.YesNo, _ 
       MessageBoxIcon.Warning) _ 
       = DialogResult.Yes Then 
      My.Computer.FileSystem.DeleteFile(lstbox.SelectedItem) 
      MessageBox.Show("File Has been Deleted Successfuly!", _ 
      "Siper Deleter", MessageBoxButtons.OK, MessageBoxIcon.Asterisk) 
      lstbox.Items.Clear() 
      For Each folder As String In _ 
      My.Computer.FileSystem.GetFiles(x) 
       lstbox.Items.Add(folder) 
      Next 
     End If 
    Catch ex As Exception 
     MessageBox.Show("Can't Delete This File", "Error", _ 
     MessageBoxButtons.OK, MessageBoxIcon.Error) 
    End Try 
End Sub 
Private Sub gotobtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gotobtn.Click 
    Try 
     Dim x As String 
     x = txtfolder.Text 
     lstbox.Items.Clear() 
     For Each folder As String In _ 
     My.Computer.FileSystem.GetFiles(x) 
      lstbox.Items.Add(folder) 
     Next 
    Catch ex As Exception 
     MessageBox.Show("Write An Address Then Click ^Goto^", _ 
     "Super Deleter", MessageBoxButtons.OK, _ 
     MessageBoxIcon.Information) 
    End Try 
End Sub 

End Class 
+5

提升的权限的应用程序需要在某些目录作用,窗口根文件夹(通常“C:\”)是其中的一个。 – Plutonix

+0

为什么投了票? – chrisl08

回答

0

1)lstbox.SelectedItem.tostring

2取代lstbox.SelectedItem)你必须检查文件是否已经存在使用if system.io.file.exists(lstbox.SelectedItem.toString) then : DO SOMETHING : end if

3)使用System.IO.File.Delete ("YOUR FILE")代替My.Computer.FileSystem.DeleteFile

和用于坏langage抱歉= P