How do i rename a file in the current users \AppDat\Local folder
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How do i rename a file in the current users \AppDat\Local folder

  1. #1
    Join Date
    Mar 2010
    Posts
    2

    How do i rename a file in the current users \AppDat\Local folder

    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

    Edit/Delete Message

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How do i rename a file in the current users \AppDat\Local folder

    a suggestment about current user app data:
    Code:
    My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Mar 2010
    Posts
    2

    Re: How do i rename a file in the current users \AppDat\Local folder

    Solved:
    Substitute " & Environ("USERNAME") & "
    for USERNAME

    My.Computer.FileSystem.RenameFile("C:\Users\" & Environ("USERNAME") & "\AppData\Local\XProgram\Settings.ini", "Settings2.ini")

    Thanks though I couldn't figure out how to use the
    My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData

    probably easy I just don't know how to program
    Last edited by htdw3; March 14th, 2010 at 11:27 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center