EXIFに従ってファイルの日付を変更する

デジタルソープディッシュを入手した後、キャプチャしたファイルを少なくとも季節ごとにカタログ化する必要がありました。 しかし、判明したように、カメラからコピーした後、ファイルの変更日はコピー日に設定され、実際の撮影時間を見つけるには、EXIF情報またはファイル属性を調べる必要があります。 もちろん、自尊心のあるファイル表示プログラムはEXIFから撮影日を抽出できますが、この方法は私にとって不便です。

そこで、現在のディレクトリまたは指定されたディレクトリで* .jpgファイルを検索し、調査の時刻を取得し、この時刻がファイルが変更された時刻と一致しない場合、調査の日付と時刻に従ってこの時刻を設定する小さなプログラムをC#で作成することにしました。 役に立つ人がいることを願っています。

はい、おそらく同様の機能が組み込まれたグラフィカルプログラムがありますが、私はまだC#で​​スレッドを書くという目標を持っていました



有益な情報を提供してくれたこの記事をありがとう。



using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Windows.Media.Imaging; namespace ByteProgram.DateToEXIF { class ReadFiles { static void Main(string[] args) { string curDir; curDir = Directory.GetCurrentDirectory(); IEnumerable<string> jpgFilesInDir; if (args.Length > 0) { if(args[0] == "/?") { Console.WriteLine("        "); Console.WriteLine(": "); Console.WriteLine("    -    "); Console.WriteLine(" <> -    "); return; } if (Directory.Exists(args[0])) { jpgFilesInDir = Directory.EnumerateFiles(args[0], "*.jpg"); //      } else { Console.WriteLine("   "); return; } } else { jpgFilesInDir = Directory.EnumerateFiles(curDir, "*.jpg"); //      } FileInfo fInf; foreach (string currentFile in jpgFilesInDir) //    { fInf = new FileInfo(currentFile); Console.WriteLine(" : {0}", fInf.Name); ReadExifInfo rex = new ReadExifInfo(currentFile); try { if (rex.CreateTime.Date.Year > 1980) { Console.WriteLine(" : {0}", rex.CreateTime); if (fInf.LastWriteTime != rex.CreateTime) { Console.WriteLine("    ."); fInf.LastWriteTime = rex.CreateTime; } else { Console.WriteLine(" ,   ."); } } else { Console.WriteLine("  ."); } } catch (Exception e) { Console.WriteLine(e.Message); } } } } class ReadExifInfo { //  EXIF    private DateTime creationTime; private FileStream Foto; private BitmapMetadata TmpImgEXIF; public ReadExifInfo (string fileName) { // try { Foto = File.Open(fileName, FileMode.Open, FileAccess.Read); //     fileName   } catch (Exception) { Console.WriteLine("  "); } try { JpegBitmapDecoder decoder = new JpegBitmapDecoder(Foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default); //""     decoder TmpImgEXIF = (BitmapMetadata)decoder.Frames[0].Metadata.Clone(); //    creationTime = Convert.ToDateTime(TmpImgEXIF.DateTaken); //    Foto.Close(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("  EXIF ."); Foto.Close(); } } public DateTime CreateTime { //     get { return creationTime; } } } }
      
      






All Articles