示例#1
0
        DirectoryInfoEx PrepateDirectoryForCopy(DirectoryInfoEx srcDir, DirectoryInfoEx baseDir, string dirName)
        {
            bool isDirectory;

            if (!baseDir.Exists)
            {
                baseDir.Create();
            }
            if (baseDir.Contains(dirName, out isDirectory))
            {
                FileSystemInfoEx destSubItem = baseDir[dirName];

                if (!isDirectory)
                {
                    OverwriteMode overwrite = AskOverwrite(srcDir, destSubItem);
                    switch (overwrite)
                    {
                    case OverwriteMode.KeepOriginal:
                        return(null);

                    case OverwriteMode.Replace:
                        destSubItem.Delete();
                        return(baseDir.CreateDirectory(dirName));
                    }
                    throw new NotImplementedException("OverwriteMode");
                }
                else
                {
                    return(destSubItem as DirectoryInfoEx);
                }
            }
            else
            {
                return(baseDir.CreateDirectory(dirName));
            }
        }
        public void CopyAllFix(string sourcePath, string destinationPath)
        {
            var directories = DirectoryInfoEx.GetDirectories(sourcePath, "*.*", SearchOption.AllDirectories);

            foreach (var srcDirPath in directories)
            {
                string tempDestPath = Uri.UnescapeDataString(srcDirPath.FullName.Replace(sourcePath, destinationPath, StringComparison.OrdinalIgnoreCase));
                if (DirectoryInfoEx.CreateDirectory(tempDestPath, out string errorMessage) != 0)
                {
                    ErrorLog.Inst.LogError(errorMessage);
                }
            }
            var files = DirectoryInfoEx.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories);

            foreach (var srcFilePath in files)
            {
                string tempDestPath = Uri.UnescapeDataString(srcFilePath.FullName.Replace(sourcePath, destinationPath, StringComparison.OrdinalIgnoreCase));
                File.Copy(srcFilePath.FullName, tempDestPath, true);
            }
        }
示例#3
0
        DirectoryInfoEx PrepateDirectoryForCopy(DirectoryInfoEx srcDir, DirectoryInfoEx baseDir, string dirName)
        {
            bool isDirectory;
            if (!baseDir.Exists)
                baseDir.Create();
            if (baseDir.Contains(dirName, out isDirectory))
            {
                FileSystemInfoEx destSubItem = baseDir[dirName];

                if (!isDirectory)
                {
                    OverwriteMode overwrite = AskOverwrite(srcDir, destSubItem);
                    switch (overwrite)
                    {
                        case OverwriteMode.KeepOriginal :
                            return null;
                        case OverwriteMode.Replace :
                            destSubItem.Delete();
                            return baseDir.CreateDirectory(dirName);
                    }
                    throw new NotImplementedException("OverwriteMode");
                }
                else return destSubItem as DirectoryInfoEx;
            }
            else return baseDir.CreateDirectory(dirName);
        }