예제 #1
0
        private void Rename(string sourceFileName, string destFileName, CopyOptions copyOptions)
        {
            if (File.Exists(destFileName))
            {
                var sourceFileInfo = new FileInfo(sourceFileName);
                var destFileInfo   = new FileInfo(destFileName);
                var comparer       = new FileDateComparer(sourceFileInfo, destFileInfo, copyOptions.CompareDateOptions);

                var renamedFilename = GetCountedUpExtension(destFileName);


                switch (copyOptions.CopyStrategy)
                {
                default:
                    throw new NotSupportedException();

                case CopyStrategy.RenameNew:
                    RenameNew(sourceFileName, destFileName, comparer, renamedFilename);
                    break;

                case CopyStrategy.RenameOld:
                    RenameOld(sourceFileName, destFileName, comparer, renamedFilename);
                    break;
                }
            }
            else
            {
                File.Copy(sourceFileName, destFileName);
            }
        }
예제 #2
0
        private void RenameNew(string sourceFileName, string destFileName, FileDateComparer comparer, string renamedFilename)
        {
            var destFileInfo = new FileInfo(destFileName);

            if (comparer.NewFile.FullName == destFileInfo.FullName)
            {
                File.Move(destFileName, renamedFilename);
                File.Copy(sourceFileName, destFileName);
            }
            else if (comparer.OldFile.FullName == destFileInfo.FullName)
            {
                File.Copy(sourceFileName, renamedFilename);
            }
        }
예제 #3
0
        private void RenameOld(string sourceFileName, string destFileName, FileDateComparer comparer, string renamedFilename)
        {
            var destFileInfo = new FileInfo(destFileName);

            if (comparer.OldFile.FullName == destFileInfo.FullName)
            {
                logger.LogDebug("RenameOldMove | Move {0} to {1}", destFileName, renamedFilename);
                logger.LogDebug("RenameOldMove | Copy {0} to {1}", sourceFileName, destFileName);
                File.Move(destFileName, renamedFilename);
                File.Copy(sourceFileName, destFileName);
            }
            else if (comparer.NewFile.FullName == destFileInfo.FullName)
            {
                logger.LogDebug("RenameOldCopy | Copy {0} to {1}", sourceFileName, renamedFilename);
                File.Copy(sourceFileName, renamedFilename);
            }
        }