协助Copy&粘贴VB系统

时间:2013-11-23 20:27:24

标签: vb.net

系统的工作原理是,只要gta_sa进程停止运行,它就会将浏览cmdFile时选择的文件复制到cmdStorage的位置。我现在遇到的问题是它不会将新文件存储在.txt中,而是存储为.file。它是可以打开的,但不是默认的。

另外,我不确定如何检测最近关闭gtasa进程的时间,因此如果进程处于活动状态,我必须使用。我非常感谢你的帮助,谢谢。**

编辑:也许它需要使用计时器?不确定,再次感谢。

Imports System.Diagnostics 
Imports System Imports System.ComponentModel 

Public Class frmChatLog
    Dim ofdDone
    Dim fldDone
    Dim Completed

    Private Sub cmdStorage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdStorage.Click
        Using fld As New FolderBrowserDialog()
            If fld.ShowDialog() = Windows.Forms.DialogResult.OK Then
                MessageBox.Show("Selected " & fld.SelectedPath)
                fldDone = fld.SelectedPath
                cmdStorage.Enabled = False
            End If
        End Using
    End Sub

    Private Sub cmdFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdFile.Click
        Using ofd As New OpenFileDialog()
            If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
                MessageBox.Show("Selected " & ofd.FileName)
                ofdDone = ofd.FileName
                cmdFile.Enabled = False
            End If
        End Using
    End Sub

    Private Sub cmdStart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdStart.Click
        If cmdFile.Enabled = False And cmdStorage.Enabled = False Then
            Do Until Process.GetProcessesByName("gta_sa").Count > 0
                If Process.GetProcessesByName("gta_sa").Count > 0 Then
                    MsgBox("Game is on")

                Else
                    System.IO.File.Move(ofdDone, fldDone & "\" & Today.Now.ToString("ddMMyyHHmmss"))
                    Completed = fldDone & "\" & Today.Now.ToString("ddMMyyHHmmss")
                    Completed.ChangeExtension(".txt")
                    Exit Do
                End If
            Loop

        End If
    End Sub 
End Class

1 个答案:

答案 0 :(得分:0)

  

我现在的问题是它不会将新文件存储在.txt中,而是存储为.file。

要解决此问题,请在代码底部附近更改此行:

System.IO.File.Move(ofdDone, fldDone & "\" & Today.Now.ToString("ddMMyyHHmmss"))

到此:

File.Move(ofdDone, Path.Combine(fldDone, Now.ToString("ddMMyyHHmmss") & ".txt"))

然后摆脱提及Completed变量的任何行。您可能还需要在文件顶部添加Imports System.IO