Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dim newName As String = String.Format("{0}.exe", Path.GetRandomFileName().Replace(".", ""))
        Dim oldName As String = "C:\j\WindowsApplication1.exe"
        If File.Exists(oldName) Then
            File.Move(oldName, newName)
            Dim lngMoveFile As Long
            lngMoveFile = MoveFile("C:\test.exe", My.Computer.FileSystem.SpecialDirectories.Desktop & Application.ExecutablePath)

I want my code to move an executeable file to the desktop, and I want the application to find the current file name, because I use "GetRandomFileName" to change the filename. I used:
Application.ExecutablePath
Why is that wrong?

What I have tried:

Dim newName As String = String.Format("{0}.exe", Path.GetRandomFileName().Replace(".", ""))
        Dim oldName As String = "C:\j\WindowsApplication1.exe"
        If File.Exists(oldName) Then
            File.Move(oldName, newName)
            Dim lngMoveFile As Long
            lngMoveFile = MoveFile("C:\test.exe", My.Computer.FileSystem.SpecialDirectories.Desktop & Application.ExecutablePath)
Posted
Updated 17-Jul-17 11:58am
v5

1 solution

Nevermind:
lngMoveFile = MoveFile(My.Computer.FileSystem.SpecialDirectories.Desktop & "\" & IO.Path.GetFileName(Application.ExecutablePath), "C:\NAME.exe") 'paths of current and 
 
Share this answer
 
Comments
PIEBALDconsult 17-Jul-17 18:03pm    
Please don't answer your own question; just use "Improve question".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900