如何将打开的对话框中打开的文件复制到vb.net中的其他位置

时间:2017-07-04 00:33:46

标签: vb.net ffmpeg

我已经启动了一个新的应用程序,将视频转换为图像,然后将图像转换为gif 如果我把我的视频放在同一个文件夹的一边,但是如果我没把我的视频放在项目的同一个文件夹中,那么ffmpeg就说没有这样的文件或目录。我点击选择我的文件与openfiledialog,如何将我选择的视频复制或移动到正确的目录C:\ avitogifconverter \

我已经尝试将文件移动到其他位置,但是我尝试将文件移动到其他位置,它说我找不到目录但目录存在。我在这里想念的是代码

这是我的代码

Imports System.Diagnostics
Imports System.ComponentModel
Imports System
Imports System.IO
Imports System.IO.Compression
Imports System.Windows.Forms
Imports System.Net

Public Class Form1
Dim fpsx = 10
Dim video = ""
Dim startInfo As New ProcessStartInfo("ffmpeg.exe")
Dim frame As Long 'individual frames
Dim tempdir As String = "C:\avitogifconverter\" ' images temp directory
Dim DestPath As String = "C:\avitogifconverter\"
Public Declare Auto Function FindWindowNullClassName Lib "user32.dll" Alias "FindWindow" (ByVal lpClassname As Integer, ByVal lpWindownName As String) As Integer
Dim Counter As Integer = 0

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    My.Computer.FileSystem.CreateDirectory(tempdir)
    TextBox1.Text = "exp:-->video.avi or webm or flv"
    TextBox1.Clear()
    TextBox2.Text = fpsx


End Sub


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    fpsx = TextBox2.Text
    TextBox2.Text = fpsx

    Dim p As Process = Process.Start("cmd", "/k ffmpeg.exe -i " + TextBox1.Text + " -framerate 5/1 -filter:v fps=" + TextBox2.Text + " C:\avitogifconverter\out%02d.jpg")
    p.WaitForExit()

    If p.HasExited Then
        MsgBox("The Extraction Are Finish...")
    End If

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs)

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


    If (OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK) Then
        'TextBox1.Text = OpenFileDialog1.FileName
        'TextBox1.Text = System.IO.Path.GetFileName(OpenFileDialog1.FileName)
        TextBox1.Text = System.IO.Path.GetDirectoryName(OpenFileDialog1.FileName)
        Dim newdialog As New OpenFileDialog()
        If newdialog.ShowDialog() = DialogResult.OK Then
            System.IO.File.Copy(newdialog.FileName, tempdir)
            MessageBox.Show(System.IO.Path.GetDirectoryName(newdialog.FileName) & "\" & System.IO.Path.GetFileName(newdialog.FileName))
        End If
    End If
    If TextBox1.Text = Nothing Then
        Return
    End If
    If TextBox1.Text <> Nothing Then
        'My.Computer.FileSystem.CopyFile(TextBox1.Text, DestPath)
    End If

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    Dim args As String 'declare args
    args = " -i C:\avitogifconverter\out%02d.jpg -r 10 C:\avitogifconverter\out.gif "
    'args = " -i C:\avitogifconverter\out%02d.jpg -c:v libx264 -r 30 -pix_fmt yuv420p C:\avitogifconverter\out.mp4 "
    Dim proc As New Process
    Dim proci As New ProcessStartInfo
    proci.FileName = My.Application.Info.DirectoryPath & "\ffmpeg.exe"
    proci.Arguments = args
    proci.WindowStyle = ProcessWindowStyle.Hidden
    proci.CreateNoWindow = True
    proci.UseShellExecute = False
    proc.StartInfo = proci
    proc.Start()
    Do Until proc.HasExited = True
        Me.Text = "Saving"
    Loop
    Me.Text = "your video done"

    MsgBox("Done")
    Dim directoryName As String = "C:\avitogifconverter\"
    For Each deleteFile In Directory.GetFiles(directoryName, "*.jpg", SearchOption.TopDirectoryOnly)
        File.Delete(deleteFile)
    Next

    'IO.Directory.Delete(tempdir, True)
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    Form2.Show()

End Sub
End Class

1 个答案:

答案 0 :(得分:0)

我不知道你为什么使用2个OpenFileDialog,但无论如何你都没有正确使用System.IO.File.Copy方法。两个参数都必须是 FILE PATHS。您的错误是您将第二个参数用作 DIRECTORY PATH