它在调试模式下完美运行,但是当我运行构建的文件并按下保存按钮时,它给了我“进程无法访问文件,因为它正被另一个进程使用”未处理的异常错误(它加载但之后不保存)。任何建议,请。
Imports System.IO
Public Class DL1
Function DirExists(ByVal DirName As String) As Boolean
On Error GoTo ErrorHandler
DirExists = GetAttr(DirName) And vbDirectory
ErrorHandler:
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub LoadGlink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadGlink.Click
GlinkList.Items.Clear()
Dim fileReader As System.IO.StreamReader
fileReader = _
My.Computer.FileSystem.OpenTextFileReader("c:\Source\DL1\Glink.txt")
Dim mystring() As String = fileReader.ReadToEnd.Split(vbNewLine)
GlinkList.Items.AddRange(mystring)
fileReader.Close()
Me.Controls("Glinklist").Focus()
End Sub
Private Sub linktochrome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles linktochrome.Click
If GlinkList.SelectedItem IsNot Nothing Then
' selected item is sglink
Dim sglink = GlinkList.SelectedItem.ToString
Process.Start("C:\Users\1\AppData\Local\Google\Chrome\Application\chrome.exe", sglink)
End If
Me.Controls("Glinklist").Focus()
End Sub
Private Sub movetofol_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movetofol.Click
Dim strDir As String
strDir = "C:\Users\1\Downloads\Glink\" & "\" & SFoltext.Text
If DirExists(Trim(strDir)) = False Then
MkDir(Trim(strDir))
End If
For Each f As String In Sresult1.Items
Dim f_name As String = Path.GetFileName(f)
My.Computer.FileSystem.MoveFile(f, strDir & "\" & f_name)
Next
Sresult1.Items.Clear()
GlinkList.Items.Remove(GlinkList.SelectedItem)
End Sub
Private Sub ChecKDL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChecKDL.Click
Sresult1.Items.Clear()
Dim fileList As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
fileList = My.Computer.FileSystem.GetFiles("C:\Users\1\Downloads\")
For Each foundFile As String In fileList
Sresult1.Items.Add(foundFile)
Next
End Sub
Private Sub Bsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bsave.Click
Dim i As Integer
'Saves Glinklist
Dim path As String = System.IO.Path.Combine("c:\Source\DL1\", "Glink.txt")
Using fs As New System.IO.FileStream(path, IO.FileMode.Create)
Using w As IO.StreamWriter = New IO.StreamWriter(fs)
For i = 0 To GlinkList.Items.Count - 1
w.WriteLine(GlinkList.Items.Item(i))
Next
w.Close()
End Using
End Using
End Sub
Private Sub RMselec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RMselec.Click
GlinkList.Items.Remove(GlinkList.SelectedItem)
Me.Controls("Glinklist").Focus()
End Sub
End Class