0

So I need somone to tell me how to fix this code. I'm trying to rename a file which is in C:\%appdata%\Roaming\.minecraft\bin\XenonUpdate.jar to minecraft.jar. The code I am using is:

My.Computer.FileSystem.RenameFile("C:\%appdata%\Roaming\.minecraft\bin\XenonUpdate.jar", "minecraft.jar")

Can someone fix this?

Juan Lee
  • 5
  • 1

2 Answers2

3

%appdata% not not a valid path, rather it denotes a special folder that you can get by using Environment.GetFolderPath, once a get the %appdata% path, you can easily rename file.

    Dim folder As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
    Dim file_to_rename = Path.Combine(folder, ".minecraft\bin\XenonUpdate.jar")
    My.Computer.FileSystem.RenameFile(file_to_rename, "minecraft.jar")
Parimal Raj
  • 20,189
  • 9
  • 73
  • 110
0

File handling functions do not deal with environment variable expansion, %appdata%. You need to do this yourself.

My VB.Net is non-existent, but I think it would look like

Dim path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Dim from = path + "\.minecraft..."
Dim to = path + "\.minecraft..."
My.Computer.FileSystem.RenameFile(from, to)

Also, see C# getting the path of %AppData%

Community
  • 1
  • 1
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73