コード例 #1
0
        public void Execute(string path, string filter)
        {
            var files = _fileSystemProxy.GetAllFilesInDirectory(path, filter);

            foreach (FileInfo file in files)
            {
                try
                {
                    string newFilename;
                    string newDirectoryname;
                    using (FileStream fileStream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
                    {
                        var dateTaken = _imageProcessor.GetDateTakenFromImage(fileStream);
                        newFilename      = _fileNameFormatter.FormatFileName(file.Name, dateTaken);
                        newDirectoryname = _directoryNameFormatter.FormatDirectoryName(file.DirectoryName, dateTaken);
                    }
                    _fileSystemProxy.CreateFolderIfNotExists(newDirectoryname);
                    _fileSystemProxy.Rename(file.DirectoryName, file.Name, newDirectoryname, newFilename);
                }
                catch
                {
                }
            }
        }