Exemplo n.º 1
0
        public static IEnumerable <FileRecord> GetFileRecords(string sourceDir)
        {
            var files = System.IO.Directory.EnumerateFiles(sourceDir, "*", System.IO.SearchOption.AllDirectories);

            foreach (var fileName in files)
            {
                var creationDate   = MediaFileTools.ReadDateTaken(fileName);
                var relativePath   = fileName.Replace(sourceDir + "\\", "");
                var creationYear   = creationDate.Year.ToString();
                var creationMonth  = creationDate.Month.ToString("D2");
                var shortFileName  = fileName.Split(new [] { "/", "\\" }.ToArray(), StringSplitOptions.RemoveEmptyEntries).Last();
                var outputFilepath = CalculateDestinationPath(creationYear, creationMonth, shortFileName);
                var fileInfo       = new FileInfo(fileName);
                var checkSum       = shortFileName.ToLower() + fileInfo.Length + creationDate;
                var record         = new FileRecord
                {
                    Filename        = shortFileName,
                    SourcePath      = fileName,
                    Extension       = shortFileName.Split('.').Last().ToLower(),
                    Year            = creationYear,
                    Month           = creationMonth,
                    Timestamp       = creationDate,
                    DestinationPath = outputFilepath,
                    RelativePath    = relativePath,
                    Checksum        = checkSum,
                    Size            = fileInfo.Length
                };
                yield return(record);
            }
        }
Exemplo n.º 2
0
        private static void DebugPath(string path)
        {
            var date = MediaFileTools.ReadDateTaken(path);

            Console.WriteLine("Calculated date is: " + date);
        }