Code Snippet
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.IO;
- namespace dircontrast
- {
- class Program
- {
- static void Main(string[] args)
- {
- filename();
- }
- private static void filename()
- {
- //目?录?下?文?件t名?对?±è
- Console.WriteLine("ê?è?路·径?:");
- string dir1;
- dir1 = Console.ReadLine();
- if (!Directory.Exists(dir1)) Console.WriteLine("路·径?′í误ó");
- Console.WriteLine("ê?è?路·径?:");
- string dir2;
- dir2 = Console.ReadLine();
- if (!Directory.Exists(dir2)) Console.WriteLine("路·径?′í误ó");
- string[] filename1 = Directory.GetFiles(dir1);
- string[] filename2 = Directory.GetFiles(dir2);
- for (int i = 0; (i < filename2.Length) && (i < filename1.Length); i++)
- {
- int t1 = filename1.ElementAt(i).LastIndexOf('\\');
- int t2 = filename2.ElementAt(i).LastIndexOf('\\');
- string tmp1 = filename1.ElementAt(i).Substring(t1 + 1);
- string tmp2 = filename2.ElementAt(i).Substring(t2 + 1);
- if (tmp1 != tmp2)
- {
- Console.WriteLine(filename1.ElementAt(i) + " " + filename2.ElementAt(i));
- }
- }
- }
- private static void dircompare()//目?录?对?±è
- {
- Console.WriteLine("ê?è?路·径?:");
- string dir1;
- dir1=Console.ReadLine();
- if (!Directory.Exists(dir1)) Console.WriteLine("路·径?′í误ó");
- Console.WriteLine("ê?è?路·径?:");
- string dir2;
- dir2 = Console.ReadLine();
- if (!Directory.Exists(dir2)) Console.WriteLine("路·径?′í误ó");
- string[] files1 = Directory.GetDirectories(dir1);
- string[] files2 = Directory.GetDirectories(dir2);
- for (int i = 0;(i<files2.Length)&&(i<files1.Length) ; i++)
- {
- int t1 = files1.ElementAt(i).LastIndexOf('\\');
- int t2 = files2.ElementAt(i).LastIndexOf('\\');
- string tmp1=files1.ElementAt(i).Substring(t1 + 1);
- string tmp2 = files2.ElementAt(i).Substring(t2 + 1);
- if (tmp1 != tmp2)
- {
- Console.WriteLine(files1.ElementAt(i)+" "+files2.ElementAt(i));
- }
- }
- }
- }
- }
那天同学说有个这样的工具就好了,我想自己写个不就得了,写了个初步的文件名对比的程序