|
|
|
Forum Newbie
      
Group: Forum Members
Last Login: 3/14/2010 10:31:53 AM
Posts: 2,
Visits: 4
|
|
How do i rename a file in the current users \AppDat\Local folder (relative path)
Im using Visual Studio 2008
This is my first program
I renamed the program for the forum.
If I remove the paths and execute my .exe from the \AppData\local\ folder where the settings.ini file is it works fine, but I don't want have to run the program from there.
I tried using %Username% for relative paths, but the computer can't follow the path. Do i have to write code to get the current username or how do programmers do this?
Here's part of the program
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If My.Computer.FileSystem.FileExists("C:\Users\%Username%\AppData\Local\X PROGRAM\Settings2.ini") Then
MsgBox("Already loaded")
Else
' Kill all X PROGRAM process
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("X PROGRAM")
For Each p As Process In pProcess
p.Kill()
Next
MsgBox("Working...")
My.Computer.FileSystem.RenameFile("C:\Users\%Username%\AppData\Local\X PROGRAM\Settings.ini", "Settings2.ini")
My.Computer.FileSystem.RenameFile("C:\Users\%Username%\AppData\Local\X PROGRAM\Settings1.ini", "Settings.ini")
System.Diagnostics.Process.Start("C:\Program Files\X PROGRAM\xprogram.exe")
End If
End Sub
Here is the error
Code:
ERROR MESSAGE BOX
Unhandled exception has occurred in your application. If you click ATA Continue, the application will ignore this error and attempt to
continue. If you click Quit, the application will close immediately.
Could not find file
C:\Users\%Username%\AppData\Local\X PROGRAM\
I'll try and answer any questions
Any help you guys can offer will help
Or if you could explain why this won't work
Is this the right forum or should I try a different website?
Thanks
|
|
|
|
|
Forum Newbie
      
Group: Forum Members
Last Login: 3/14/2010 10:31:53 AM
Posts: 2,
Visits: 4
|
|
SOLVED
substitute " & Environ("USERNAME") & "
for USERNAME
My.Computer.FileSystem.RenameFile("C:\Users\" & Environ("USERNAME") & "\AppData\Local\XPROGRAM\Settings.ini", "Settings2.ini")
|
|
|
|