Bloom.WebLibraryIntegration.BloomS3Client.CopyDirectory C# (CSharp) Method

CopyDirectory() private static method

copy directory and all subdirectories
private static CopyDirectory ( string sourceDirName, string destDirName ) : bool
sourceDirName string
destDirName string Note, this is not the *parent*; this is the actual name you want, e.g. CopyDirectory("c:/foo", "c:/temp/foo")
return bool
        private static bool CopyDirectory(string sourceDirName, string destDirName)
        {
            bool success = true;
            var sourceDirectory = new DirectoryInfo(sourceDirName);

            if (!sourceDirectory.Exists)
            {
                throw new DirectoryNotFoundException(
                    "Source directory does not exist or could not be found: "
                    + sourceDirName);
            }

            if (!Directory.Exists(destDirName))
            {
                Directory.CreateDirectory(destDirName);
            }

            foreach (FileInfo file in sourceDirectory.GetFiles())
            {
                var destFileName = Path.Combine(destDirName, file.Name);
                try
                {
                    file.CopyTo(destFileName, true);
                }
                catch (Exception ex)
                {
                    if (!(ex is IOException || ex is UnauthorizedAccessException || ex is SecurityException))
                        throw;
                    // Maybe we don't need to write it...it hasn't changed since a previous download?
                    if (!SameFileContent(destFileName, file.FullName))
                        success = false;
                }
            }

            foreach (DirectoryInfo subdir in sourceDirectory.GetDirectories())
            {
                success = CopyDirectory(subdir.FullName, Path.Combine(destDirName, subdir.Name)) && success;
            }
            return success;
        }