コード例 #1
0
        public void CloneModificationDates(string sourcePath, string sourceExtension, string targetPath, string targetExtension)
        {
            try
            {
                var originalFiles = Directory.GetFiles(sourcePath, string.Format("*.{0}", sourceExtension));
                m_logger.LogFormat(Resources.Toolkit_CloneModificationDates_Found__0__files, originalFiles.Length);

                int numberOfItemsModified = 0;
                var videoExtensions       = VideoInfo.GetVideoExtensions();
                var imageExtensions       = ImageInfo.GetImageExtensions();

                foreach (var originalFile in originalFiles)
                {
                    var originalFileName  = Path.GetFileNameWithoutExtension(originalFile);
                    var convertedFilePath = string.Format("{0}.{1}", Path.Combine(targetPath, originalFileName), targetExtension);
                    if (File.Exists(convertedFilePath))
                    {
                        DateTime?originalFileDate      = null;
                        var      originalFileExtension = "*" + Path.GetExtension(originalFile).ToLower();

                        if (videoExtensions.Contains(originalFileExtension))
                        {
                            originalFileDate = VideoInfo.GetVideoFileTakenDate(originalFile);
                        }
                        else if (imageExtensions.Contains(originalFileExtension))
                        {
                            originalFileDate = ImageInfo.GetTakenDate(originalFile);
                        }

                        if (originalFileDate == null)
                        {
                            originalFileDate = new[] { File.GetLastWriteTime(originalFile), File.GetCreationTime(originalFile) }.Min();
                        }


                        m_logger.LogFormat(Resources.Toolkit_CloneModificationDates_Updating__0__from__1__to__2_, originalFileName, File.GetLastWriteTime(convertedFilePath), originalFileDate);
                        File.SetCreationTime(convertedFilePath, originalFileDate.Value);
                        File.SetLastWriteTime(convertedFilePath, originalFileDate.Value);

                        numberOfItemsModified++;
                    }
                }

                m_logger.LogFormat(Resources.Toolkit_CloneModificationDates_Modified__0__files, numberOfItemsModified);
            }
            catch (Exception ex)
            {
                m_logger.LogFormat(Resources.Toolkit_CloneModificationDates_Error___0_, ex);
            }
        }
コード例 #2
0
        public void CloneModificationDates(string sourcePath, string sourceExtension, string targetPath, string targetExtension)
        {
            try
            {
                var originalFiles = Directory.GetFiles(sourcePath, string.Format("*.{0}", sourceExtension));

                int numberOfItemsModified = 0;
                var videoExtensions       = VideoInfo.GetVideoExtensions();
                var imageExtensions       = ImageInfo.GetImageExtensions();

                foreach (var originalFile in originalFiles)
                {
                    var originalFileName  = Path.GetFileNameWithoutExtension(originalFile);
                    var convertedFilePath = string.Format("{0}.{1}", Path.Combine(targetPath, originalFileName), targetExtension);
                    if (File.Exists(convertedFilePath))
                    {
                        DateTime?originalFileDate      = null;
                        var      originalFileExtension = "*" + Path.GetExtension(originalFile).ToLower();

                        if (videoExtensions.Contains(originalFileExtension))
                        {
                            originalFileDate = VideoInfo.GetVideoFileTakenDate(originalFile);
                        }
                        else if (imageExtensions.Contains(originalFileExtension))
                        {
                            originalFileDate = ImageInfo.GetTakenDate(originalFile);
                        }

                        if (originalFileDate == null)
                        {
                            originalFileDate = new[] { File.GetLastWriteTime(originalFile), File.GetCreationTime(originalFile) }.Min();
                        }


                        File.SetCreationTime(convertedFilePath, originalFileDate.Value);
                        File.SetLastWriteTime(convertedFilePath, originalFileDate.Value);

                        numberOfItemsModified++;
                    }
                }
            }
            catch
            {
            }
        }
コード例 #3
0
 protected override string[] GetFolderSearchPatternsList()
 {
     return(ImageInfo.GetImageExtensions());
 }