So how can I delete a old file once it's updated? I'm making a program were once it's updated to delete the old version. I don't have a installer so I wouldn't know the location of the file. How can I delete it after it's updated and I don't know were the user put the file that I need to delete? I've searched and everything that shows up you need to have the path.
How to delete my old program file?
116 views Asked by user3329318 At
2
There are 2 answers
0

In the above answer, you can put quotes around the fileupdatepath and application.executablepath and the code will work even if if there is a space in the file locations. The final code will look like this:
fileupdatepath = "The path to your file which is the updated one you downloaded."
Dim pi As New ProcessStartInfo("cmd.exe", String.Format("/c ping 1.1.1.1 -n 1 -w 15000 >NUL & move /y {0} {1} & start {1}", """" & fileupdatedpath& """", """" & Application.ExecutablePath & """")) With {.CreateNoWindow = True, .UseShellExecute = False}
Process.Start(pi)
Application.Exit()
You could use ClickOnce as suggested, but if you really don't want to use any "external" tools.. this might do the job:
Sorry for my coding, i use this snipet in some of my projects aswell and it works quite good.
This is used in the application that is being updated...
This waits 15s to ensure the current application is closed properly before starting the new one, this is used if the same name and application path needs to be kept, as the move command is being used to replace any files with the same name., if not you can just start the new one, close the current, and delete the current application file...
Note: 'This works if the application path has no special characters like '#' or ' '