VB.net从桌面移动文件

时间:2015-01-13 01:26:42

标签: vb.net

我正在为mod包制作一个启动器。我拥有工作所需的一切。问题是,无论如何,启动器可以在我给它们之后从其他用户桌面移动东西因为我知道不是每个人在他们的用户文件中都有相同的名称,所以他们是一个全局的方式来到某人桌面而不得不改变它为每个人。就像我的桌面位于C:\ Users \ Zach \ Desktop不是每个人的用户文件都是Zach这是我目前的所有代码。我也在寻求帮助,而不是有人为我做这件事。

Public Class Form1

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    Me.Close()
End Sub

Private Sub PictureBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseEnter
    PictureBox1.Image = My.Resources.Exit_2
End Sub

Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
    PictureBox1.Image = My.Resources._Exit
End Sub

Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
    Process.Start("FILE NAME")
    MsgBox("Downloading Arma 3 Mods")
End Sub

Private Sub PictureBox2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.MouseEnter
    PictureBox2.Image = My.Resources.Download_2

End Sub

Private Sub PictureBox2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.MouseLeave
    PictureBox2.Image = My.Resources.Download
End Sub

Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
    Dim path As String = "c:\"
    Dim path2 As String = "c:\"

    Try
        If File.Exists(path) = False Then
            ' This statement ensures that the file is created, 
            ' but the handle is not kept. 
            Dim fs As FileStream = File.Create(path)
            fs.Close()
        End If

        ' Ensure that the target does not exist. 
        If File.Exists(path2) Then
            File.Delete(path2)
        End If

        ' Move the file.
        File.Move(path, path2)
        Console.WriteLine("{0} moved to {1}", path, path2)

        ' See if the original file exists now. 
        If File.Exists(path) Then
            Console.WriteLine("The original file still exists, which is unexpected.")
        Else
            Console.WriteLine("The original file no longer exists, which is expected.")
        End If
    Finally
    End Try
End Sub


Private Sub PictureBox3_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox3.MouseEnter
    PictureBox3.Image = My.Resources.Move_File_2
End Sub

Private Sub PictureBox3_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox3.MouseLeave
    PictureBox3.Image = My.Resources.Move_File
End Sub
End Class

1 个答案:

答案 0 :(得分:0)

您可以使用Environment.GetFolderPath方法: Check full explanation here!

在这种情况下,使用Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)获取用户的桌面目录。

像这样:

Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory))
   End Sub 'Main
End Class 'Sample