16,554
社区成员
发帖
与我相关
我的任务
分享
Dim filename As String = "02.xls"
Dim ps() As Process = Process.GetProcesses
Dim p As Process
For i = 0 To ps.Length - 1
p = ps(i)
If p.MainWindowTitle.Contains(filename) Then
MsgBox("文件打开")
End If
Next
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using d As New OpenFileDialog
If d.ShowDialog = Windows.Forms.DialogResult.OK Then
Console.WriteLine(IsOpened(d.FileName))
End If
End Using
End Sub
Public Shared Function IsOpened(ByVal filename As String) As Boolean
Try
Dim aa As New System.IO.FileStream(filename, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
aa.Dispose()
Return True
Catch ex As Exception
Return False
End Try
End Function
If FileIO.FileSystem.FileExists(filename) Then
Else
MsgBox("文件不存在")
Exit Sub
End If
dim path as string
path="c:\temp"
On Error GoTo opend
FileIO.FileSystem.MoveFile(filename, path)
FileIO.FileSystem.MoveFile(path,filename)
MsgBox("文件未打开")
Exit Sub
opend:
MsgBox("文件打开")