MyFileInfo GetMyFileInfo(FileInfo fileInfo) { //if (fileInfo.Directory == null) //{ // Console.WriteLine($"this should neve happen, but {fileInfo.FullName} fileInfo.Directory was null, "); // return null; //} var myFileInfo = new MyFileInfo { Name = fileInfo.Name, Folder = fileInfo.Directory.ToString(), Extension = Path.GetExtension(fileInfo.Name).Replace(".", ""), Size = fileInfo.Length, Md5 = GetMd5(fileInfo.FullName) }; try { myFileInfo.DateTaken = FileNameToDateTaken(fileInfo.Name); if (string.IsNullOrEmpty(myFileInfo.DateTaken)) { var image = Image.FromFile(fileInfo.FullName); var id = image.GetPropertyItem(306); var enc = new ASCIIEncoding(); myFileInfo.DateTaken = enc.GetString(id.Value, 0, id.Len - 1); } } catch (Exception) { myFileInfo.DateTaken = fileInfo.CreationTime.ToString("yyyy:MM:dd HH:mm:ss", CultureInfo.InvariantCulture); } return(myFileInfo); }
private void FileMove(MyFileInfo mi) { try { var file = $"{mi.Folder}\\{mi.Name}"; if (!File.Exists(file)) { Console.WriteLine($"{file} does not exist"); return; } Console.Write($"\rmoving {file} ..."); if (!Directory.Exists(mi.TargetFolder)) { Directory.CreateDirectory(mi.TargetFolder); } var targetFile = $"{mi.TargetFolder}\\{mi.Name}"; if (File.Exists(targetFile)) { targetFile = $"{Path.GetDirectoryName(targetFile)}\\{Path.GetFileNameWithoutExtension(targetFile)}_{DateTime.Now.Ticks}{Path.GetExtension(targetFile)}"; } if (_move) { File.Move(file, targetFile); } else { File.Copy(file, targetFile); } } catch (Exception e) { var msg = $"failed to move {mi.Name} from {mi.Folder} to {mi.TargetFolder}\n{e.Message}"; _errors.Add(msg); Console.WriteLine(msg); } }
private string MyFileInfoToScvLine(MyFileInfo myFileInfo) { return ($"{myFileInfo.Folder}\t{myFileInfo.Name}\t{myFileInfo.Extension}\t{myFileInfo.DateTaken}\t{myFileInfo.Size}\t{myFileInfo.Md5}"); }