示例#1
0
        public void CopyDirectoryContents(DirectoryInfo source, DirectoryInfo target)
        {
            if (string.Equals(source.FullName, target.FullName, StringComparison.Ordinal))
            {
                return;
            }

            _fileSystemOperations.Create(target);
            SetUnixOwnerIfNeeded(target.FullName);

            // Copy each file into it's new directory.
            foreach (FileInfo fi in _fileSystemOperations.GetFiles(source))
            {
                _fileSystemOperations.CopyTo(fi, Path.Combine(target.ToString(), fi.Name), true);
                SetUnixOwnerIfNeeded(Path.Combine(target.ToString(), fi.Name));
            }

            // Copy each subdirectory using recursion.
            foreach (DirectoryInfo diSourceSubDir in _fileSystemOperations.GetDirectories(source))
            {
                //It's ok to create the directory here, the recursion will set the permissions on the next call
                DirectoryInfo nextTargetSubDir = _fileSystemOperations.CreateSubdirectory(target, diSourceSubDir.Name);
                CopyDirectoryContents(diSourceSubDir, nextTargetSubDir);
            }
        }