成都网站建设设计

将想法与焦点和您一起共享

vb.net删除 vbnet删除记录命令

vb.net怎么强制删除文件

先杀进程再删除文件

创新互联建站专注于中大型企业的网站建设、网站制作和网站改版、网站营销服务,追求商业策划与数据分析、创意艺术与技术开发的融合,累计客户千余家,服务满意度达97%。帮助广大客户顺利对接上互联网浪潮,准确优选出符合自己需要的互联网运用,我们将一直专注品牌网站制作和互联网程序开发,在前进的路上,与客户一起成长!

Visual Basic code

//杀进程代码

Private Sub KillProcess(ByVal processName As String)

Dim myproc As System.Diagnostics.Process = New System.Diagnostics.Process

Try

For Each thisproc As Process In Process.GetProcessesByName(processName)

If (Not thisproc.CloseMainWindow()) Then

thisproc.Kill()

End If

Next

Catch

End Try

End Sub

vb.net中,如何删除指定文本文档中的指定行的内容

Dim newfile As New List(Of String)

For Each line As String In System.IO.File.ReadAllLines("TextFile1.txt")

If Not line.StartsWith("3") Then newfile.Add(line)

Next

System.IO.File.WriteAllLines("TextFile1.txt", newfile)

建个集合,用System.IO.File的ReadAllLines读出所有内容,逐个判断,如果是需要的加入集合,如果是要删除的什么都不做,最后用WriteAllLines写入即可。

这里说明一下,上面那个代码是用来删除所有以3开头的文本行。

VB.NET怎么删除INI文件里的一个字段或键值?

1,对于INI文件,可以当做像TXT文件一样来进行读取和写入。

2,先把整个文件度出来,然后找到相应行删除(抛弃)以后,再重新写入文件。

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim MyStr As String = ""

Dim AllStr As String = ""

'获取一个可用的文件号

Dim MyFileNum As Integer = FreeFile()

'打开指定的文件,进行读取操作

FileOpen(MyFileNum, "C:\My.ini", OpenMode.Input)

Do While Not EOF(MyFileNum)

'读取一行

MyStr = LineInput(MyFileNum)

If MyStr  "b=2" Then

If AllStr = "" Then

AllStr = AllStr  MyStr

Else

AllStr = AllStr  vbCrLf  MyStr

End If

End If

Loop

FileClose(MyFileNum)   '关闭文件

'写文件

Dim MyStream As New System.IO.FileStream("C:\My.ini", IO.FileMode.Create)

Dim MyWriter As New System.IO.StreamWriter(MyStream, System.Text.Encoding.UTF8)

MyWriter.WriteLine(AllStr)

MyWriter.Flush()

MyWriter.Close()

MyStream.Close()

End Sub

End Class

vb.net删除文件

Private Sub btnRemovePath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemovePath.Click

Try

' 先建立目录以便用于后续的删除示范。

If Not Directory.Exists("D:\网易") Then

Directory.CreateDirectory(" D:\网易 \Test1")

Directory.CreateDirectory(" D:\网易 \Test2")

Directory.CreateDirectory(" D:\网易 \Test3")

End If

' 删除子目录 Test1。

Directory.Delete(" D:\网易 \Test1", True)

' 删除子目录 Test2。

Dim myDirectoryInfo As New DirectoryInfo(" D:\网易 \Test2")

myDirectoryInfo.Delete(True)

' 将目录 C:\AlexDirDemo 及其以下的文件和子目录全数删除。

Directory.Delete(" D:\网易 ", True)

Catch ex As Exception

MessageBox.Show(ex.Message)

Exit Sub

End Try

' 启动 Windows 资源管理器。

Process.Start("explorer.exe", "D:\")

End Sub


当前名称:vb.net删除 vbnet删除记录命令
分享路径:http://chengdu.cdxwcx.cn/article/dohiosj.html