1

I am trying to move a folder from one directory to another using this

System.IO.Directory.Move(tempPath, newFolder);

I am Administrator on my computer, so I should have full access. I cannot figure out why I get this exception once every two trying.

Access to the path 'D:\<myDirectory>' is denied.

kbaccouche
  • 4,575
  • 11
  • 43
  • 65
  • 1
    Perhaps there is an open file in the temp-folder? – lboshuizen Oct 30 '12 at 15:17
  • 4
    Since the question is tagged with asp.net-mvc-3, are you trying to do this from an asp.net application? If so, does the account under which the hosting process is executing have rights to both these locations? Also, administrators can still be denied directory & file access through the security configuration of said file system elements. – Hugo Oct 30 '12 at 15:19
  • @Hugo : I am doing this from an ASP MVC 3 application. And these two locations are inside another folder on which I have full control – kbaccouche Oct 30 '12 at 15:29
  • Not sure about this, but worth trying. Have you tried running your VS as administrator? I've run into this beofre. – Rahul Rumalla Oct 30 '12 at 15:38
  • @RahulNomiddlenameRumalla: Nope still not working – kbaccouche Oct 30 '12 at 15:44
  • Are you using any StreamReaders/Writers that might not have been disposed of before trying to move the directory? – hawkke Oct 30 '12 at 16:49
  • @lboshuizen was right, There was an open file in the temp-folder but I coudn't find why – kbaccouche Oct 30 '12 at 16:49

1 Answers1

2

Just because you're admin doesn't mean you can access everything. Among the things you can't necessarily access:

  • Files/directories owned by SYSTEM which don't explicitly allow admins (e.g. C:\System Volume Information)
  • Files locked by other processes with "share" settings which preclude your access
Roman Starkov
  • 59,298
  • 38
  • 251
  • 324
  • 1
    I checked the access rights of the directory in which I am doing this operation and I do have full control on it. Besides, as I said this works once and when I retry another time it gives this exception – kbaccouche Oct 30 '12 at 15:27