Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access to the path is denied

Status
Not open for further replies.

realm174

Programmer
Jan 3, 2002
154
CA
Hello people, it's been a while...

I'm trying to rename a folder located inside the %appdata% folder. I can do it in Windows Explorer no problem, but I can't do it in a batch file, nor can I do it in vb.net. Here's what I have for code:

Code:
Public Class Form1
    Public RootFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

    Private Sub btnPlay14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay14.Click
        'Rename the folders
        Try
            My.Computer.FileSystem.RenameDirectory(RootFolder & "\.minecraft.1.4", ".minecraft")
            'do other stuff... 
        Catch ex As Exception
        End Try
    End Sub
End Class

The source folder does exist, and the destination does not.

When running the code, it gets to the renamedirectory line, and jumps to the catch. Exception error is:

"Access to the path 'C:\Users\Real\AppData\Roaming\.minecraft.1.4' is denied."

I'm going to guess that it's because AppData is a protected folder? Anyway to get around that?

thanks!


Cheers,

Realm174
 

Try setting the directory's attributes to Normal and see if it works:


Public RootFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)


System.IO.File.SetAttributes(RootFolder & "\.minecraft.1.4", System.IO.FileAttributes.Normal);



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thank you for your response, that did not work unfortunately. Nothing wrong with your line of code, it went through it without error, but I'm still getting the error at the rename line. :(



Cheers,

Realm174
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top