How do i rename a file in the \AppDat\Local folder (relative path)



Programming Help Forums
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



How do i rename a file in the \AppDat\Local... Expand / Collapse
Author
Message
Posted 3/9/2010 10:39:14 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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
Post #5168
Posted 3/10/2010 4:00:36 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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")
Post #5169
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: ProgrammingHelp, Viral Unity, Matt.Hill, DaveL, Alex.D

Permissions Expand / Collapse

All times are GMT -5:00, Time now is 4:16am

Powered By InstantForum.NET v4.1.4 © 2010
Execution: 0.094. 9 queries. Compression Disabled.