0
        private void button3_Click(object sender, EventArgs e)
        {
            IEnumerable<string> fileNameList = Directory.EnumerateFileSystemEntries(sourcePath);
            foreach (var fileName in fileNameList)
            {
                FileInfo fileInfo = new FileInfo(fileName);
                File.Copy(fileName, targetPath + "\\"+ fileInfo.Name);
            }
        }

传入sourcePath以及targetPath,执行到File.Copy这步,如果sourcePath里都是文件,则正常执行复制。如含有文件夹,则迭代到文件夹的时候,报错System.UnauthorizedAccessException,路径sourcePath的访问被拒绝。请教是什么问题?

1 个回答

0

https://stackoverflow.com/que...

File.Copy(file, dest, true);
File.SetAttributes(dest, FileAttributes.Normal);