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

前端 未结 4 841
天涯浪人
天涯浪人 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:51

    That folder is a secure system folder (your bin, each drive has its own bin). Just place your file.copy into a try catch statement and ignore/log all the failures. That way you will only copy actual files and skip system files/folders.

    If you really want to avoid the try catch statement. Use the fileinfo and directory info classes to figure out which folders/files are of the system and will throw an exception.

提交回复
热议问题