Access to the path 'c:\$Recycle.Bin\S-1-5-18' is denied

前端 未结 4 838
天涯浪人
天涯浪人 2020-12-31 22:05

I have this code to copy all files from source-directory, F:\\, to destination-directory.

public void Copy(string sourceDir, string targetDir)
{         


        
4条回答
  •  灰色年华
    2020-12-31 22:37

    File system objects are subject to security. Some file system objects are secured in such a way that they can only be accessed by certain users. You are encountering a file to which the user executing the code does not have sufficient rights to access.

    The reason that you don't have access rights for this particular folder is to protect the security of the different users on the system. The folder in question is the recycle bin on that drive. And each different user has their own private recycle bin, that only they have permission to access. If anybody could access any other user's recycle bin, then users would be able to read each other's files, a clear violation of the system's security policy.

    Perhaps the simplest way around this is to skip hidden folders at the root level of the drive. That simple change would be enough to solve your problem because you surely don't want to copy recycle bins.

提交回复
热议问题