Program: 多个相机的照片合并

今天从广西回来了。为了合并路途上三个照相机(我的、大姑父的和摄像机照的)的照片,将它们按照时间顺序排列,便于今后的剪辑,所以编写了如下的小程序。简陋得很,但是完成任务了,呵呵。

基本思想是先找出三个照相机的时间差,然后统一他们的时间。接着按照自己定义好的格式进行重命名。一共两千多张的照片(5个多G),五分钟内复制完毕。搞定。

程序使用C#写的,这个速度快呀。其实应该用Python,但考虑到还不是特别熟悉。要速度嘛,就没有质量了。

如果您也需要进行文件批量的有条件性重命名,可以考虑看看我的这个程序。^_^

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

name­space File­Re­na­mer
{
    class Pro­g­ram
    {
        sta­tic void Main(string[] args)
        {
            Date­Time dt1 = DateTime.Parse(“2008–11-10  10:35:38″);
            Date­Time dt2 = DateTime.Parse(“2008–11-10  10:32:34″);
            Date­Time dt3 = DateTime.Parse(“2008–11-10  11:28:58″);
            Time­Span ts1 = dt2.Subtract(dt1);
            Time­Span ts2 = dt3.Subtract(dt1);

            string path = “C:\\Documents and Settings\\Administrator\\桌面\\广西照片”;
            string file­save = “D:\\1.txt”;
            Dire­cto­r­yInfo dirinfo = new DirectoryInfo(path);
            SortedList<string, string> sl = new SortedList<string, string>();
            foreach (Dire­cto­r­yInfo dir in dirinfo.GetDirectories())
            {
                File.AppendAllText(filesave,dir.Name + “\r\n”);
                FileInfo[] files = dir.GetFiles();
                foreach (FileInfo file in files)
                {
                    Date­Time true­time = DateTime.MinValue;
                    if (dir.Name.Contains(“主卡”)) { true­time = file.LastWriteTime; }
                    else if (dir.Name.Contains(“大姑父”)) { true­time = file.LastWriteTime.Subtract(ts1); }
                    else if (dir.Name.Contains(“摄像机”)) { true­time = file.LastWriteTime.Subtract(ts2); }
                    else { }
                    File.AppendAllText(filesave, file.Name + “\t” + file.LastWriteTime.ToString() + “\t” + truetime.ToString() + “\t” + dir.Name + “\r\n”);
                    sl.Add(truetime.Ticks.ToString() + ” — ” + dir.Name + ” — ” + file.Name, file.FullName + “|” + dir.Name);
                }
                File.AppendAllText(filesave, “\r\n\r\n”);
            }
            File.AppendAllText(filesave, “\r\n\r\n”);

            int n = 1;
            foreach (string con­tent in sl.Keys)
            {
                string[] str = sl[content].Split(new char[] { ‘|’ });
                string origin_filename = str[0];
                string coun­ter = n.ToString();
                string plus = “”;
                swi­tch (counter.Length)
                {
                    case 1:
                        plus = “000”;
                        break;
                    case 2:
                        plus = “00”;
                        break;
                    case 3:
                        plus = “0”;
                        break;
                }
                string new_filename = plus + coun­ter + ” — ” + str[1] + “.jpg”;
                Console.WriteLine(origin_filename + “\t” + new_filename);
                File.Copy(origin_filename, “D:\\photos\\” + new_filename);
                n++;
            }
        }
    }
}

No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>