为什么以及如何解决此错误? [英] Why And How Do I Fix This Error?

查看:64
本文介绍了为什么以及如何解决此错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个小的代码段,该代码段属于一个简单的清单框文件删除程序.原始程序可以使用该代码,但是我的程序无法正常运行,并返回如下异常:

``不支持给定路径的格式''.

异常发生的代码行是:

将fileInfo调为新FileInfo(item.ToString())


我试图将其应用于我的程序的源代码如下:

I have used a small code snippet which belongs to a simple checklistbox file delete program. The original program works with the code but my program does not function the same and returns an exception as follows:

''The given path''s format is not supported''.

the line of code that the exception happens to is:

Dim fileInfo As New FileInfo(item.ToString())


The source code Im trying to apply to my program is as follows:

Imports System.IO
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    For Each foundFile As String In My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.Temp, FileIO.SearchOption.SearchAllSubDirectories, "*.*")            CheckedListBox1.Items.Add(foundFile)
        Next
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        For Each item As Object In CheckedListBox1.CheckedItems
            If item.GetType() Is GetType(FileInfo) Then
            CType(item, FileInfo).Delete()

            ElseIf item.GetType() Is GetType(String) Then
                Dim fileInfo As New FileInfo(item.ToString())
                On Error Resume Next
                fileInfo.Delete()
            End If
        Next
        While CheckedListBox1.CheckedItems.Count > 0
        CheckedListBox1.Items.Remove(CheckedListBox1.CheckedItems(0))
        End While
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            For i As Integer = 0 To CheckedListBox1.Items.Count - 1
                CheckedListBox1.SetItemChecked(i, True)
            Next
        Else
            For i As Integer = 0 To CheckedListBox1.Items.Count - 1
                CheckedListBox1.SetItemChecked(i, False)
            Next
        End If
    End Sub
End Class





这段代码的问题是,我需要button3 click事件(删除)来删除与找到的项目关联的文件,而不是加载文件系统特殊目录"*.*".我的程序是扫描程序,因此需要能够删除并记住在my.resources.viruslist中找到的名称的路径.任何人都可以编写此代码来正确删除在清单框项目区域中找到的文件吗?





The problem with this code is that I need the button3 click event (delete) to delete the file that is associated with the item found and not to load the file system special directories "*.*" My program is a scanner so it needs to be able to delete and remember the paths of the names it finds in my.resources.viruslist. Can anyone write this code to properly delete files that are found in the checklistbox items area?

推荐答案

您要传递到项目中的路径是什么.

调试并查看路径-
1)路径有效吗?
2)您是否可以访问该路径.

请记住,在调试模式下和实际"执行模式下的程序路径总是不同的.
What is the path that you are passing into item.

Debug and have a look at the path -
1) is the path valid?
2) do you have access to that path.

Remember, the paths for a program in debug mode and in "real" execution mode are always different.


它在我的计算机上工作.错误消息表明您尝试创建FileInfo对象时文件名无效.是吗?
It works on my computer. The error message says that you have an invalid file name while trying to create FileInfo object. Does it?


这篇关于为什么以及如何解决此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆