注册 登录
编程论坛 VB.NET论坛

求助:在listview中显示的文件信息(包括文件名/文件路径),想实现删除功能,但不能实现彻底删除所选项的文件?

Steven_LHX 发布于 2017-10-26 22:18, 3321 次点击
大家帮帮我看看代码,问题出在哪,尝试了好多遍了,谢谢!
程序代码:
Try
            Dim dfpath As String = NodeDrives.SelectedItem.ToString
            Dim dfi As DirectoryInfo = New DirectoryInfo(dfpath)
            Dim file As FileInfo() = dfi.GetFiles(".", SearchOption.AllDirectories)
            Dim fiTemp As FileInfo
            For Each fiTemp In file
                Dim lifile() As String = {fiTemp.Name, fiTemp.FullName, fiTemp.Extension, fiTemp.LastWriteTime}
                If lifile(0) = ListView1.SelectedIndices.ToString Then
                    Dim dpath As String = fiTemp.FullName
                    Dim fi As FileInfo = New FileInfo(dpath)
                    fi.Delete()
                End If
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try


[此贴子已经被作者于2017-10-27 08:28编辑过]

7 回复
#2
xyxcc1772017-10-28 12:54
不知道彻底删除是什么意思?
#3
xyxcc1772017-10-28 12:59
程序代码:

'
Dim FileName As String
(FileName)
#4
zhangcanwei2017-11-04 07:55
看看fiTemp.FullName字符串中是否包含了非法字符
#5
zhangcanwei2017-11-04 07:56
在循环体内定义变量不好。影响速度。应该在循环体外部定义
#6
Steven_LHX2018-03-13 08:32
回复 2楼 xyxcc177
就是实现本地文件也删除。
#7
Steven_LHX2018-03-13 08:33
回复 3楼 xyxcc177
嗯嗯、已经解决了,谢谢
#8
Steven_LHX2018-03-13 08:36
回复 4楼 zhangcanwei
嗯、程序能够运行,不报错,应该不存在非法字符吧。不过确实影响速度。哈哈,,谢谢了
1