Skip to content

Commit 7c70888

Browse files
committed
Add v1 sourcecode
1 parent 6475994 commit 7c70888

7 files changed

Lines changed: 258 additions & 12 deletions

File tree

.gitignore

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
CMakeLists.txt.user
2-
CMakeCache.txt
3-
CMakeFiles
4-
CMakeScripts
5-
Testing
6-
Makefile
7-
cmake_install.cmake
8-
install_manifest.txt
9-
compile_commands.json
10-
CTestTestfile.cmake
11-
_deps
1+
Source/DuplicateFileCheck/bin
2+
Source/DuplicateFileCheck/obj
3+
Source/.vs

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
# DuplicateFileCheck
2-
Duplicate File Check 重复文件检查
2+
3+
> Duplicate File Check 重复文件检查
4+
5+
## 执行命令方式
6+
7+
> DuplicateFileCheck.exe -p C:\Github\CSharpCodes C:\Github\JingShiZiJi -w true -l C:\Temp
8+
9+
```
10+
-p 后边跟的是需要扫描的路径。
11+
-w 后边true 则输出扫描结果到日志文件。
12+
-l 后边跟的是一个目录用于保存计算结果 如果路径不存在会自动创建。
13+
```

Source/DuplicateFileCheck.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.32602.291
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DuplicateFileCheck", "DuplicateFileCheck\DuplicateFileCheck.csproj", "{94588FF7-7A19-41A5-8931-9F596097CE70}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{94588FF7-7A19-41A5-8931-9F596097CE70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{94588FF7-7A19-41A5-8931-9F596097CE70}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{94588FF7-7A19-41A5-8931-9F596097CE70}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{94588FF7-7A19-41A5-8931-9F596097CE70}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {F3E4F503-7B0D-45E1-BCE6-962DB780EC11}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<RootNamespace>DEVGIS.DuplicateFileCheck</RootNamespace>
7+
<Authors>DEVGIS</Authors>
8+
<Company>DEVGIS</Company>
9+
<Description>www.devgis.com</Description>
10+
</PropertyGroup>
11+
12+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace DEVGIS.DuplicateFileCheck
6+
{
7+
public class MyFileInfo
8+
{
9+
public string Key
10+
{
11+
get;
12+
set;
13+
}
14+
15+
public string Name
16+
{
17+
get;
18+
set;
19+
}
20+
21+
public List<MyFileInfo> DuplicateFiles
22+
{
23+
get;
24+
set;
25+
}
26+
}
27+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Security.Cryptography;
5+
using System.Text;
6+
using System.Threading;
7+
8+
namespace DEVGIS.DuplicateFileCheck
9+
{
10+
class Program
11+
{
12+
static Dictionary<string, MyFileInfo> dictMyFileInfos = null;
13+
static bool writLog = true;
14+
static string logPath = string.Empty;
15+
static List<string> paths = new List<string> {};
16+
static void Main(string[] args)
17+
{
18+
writLog = false;
19+
logPath = string.Empty;
20+
paths = new List<string>();
21+
//-p paths
22+
//-l lpath .outputlogpath
23+
//-w true false true output log
24+
if (args != null && args.Length > 0)
25+
{
26+
for (int i = 0; i < args.Length; i++)
27+
{
28+
switch (args[i].ToLower())
29+
{
30+
case "-p":
31+
for (int j = i + 1; j < args.Length; j++)
32+
{
33+
if (!args[j].StartsWith("-") && Directory.Exists(args[j]))
34+
{
35+
paths.Add(args[j]);
36+
}
37+
else
38+
{
39+
break;
40+
}
41+
}
42+
break;
43+
case "-w":
44+
try
45+
{
46+
if ("true".Equals(args[i + 1].ToLower()))
47+
{
48+
writLog = true;
49+
}
50+
else
51+
{
52+
writLog = false;
53+
}
54+
}
55+
catch
56+
{ }
57+
break;
58+
case "-l":
59+
try
60+
{
61+
string lp = args[i + 1];
62+
if (!Directory.Exists(lp))
63+
{
64+
Directory.CreateDirectory(lp);
65+
}
66+
67+
logPath = lp;
68+
}
69+
catch
70+
{ }
71+
break;
72+
break;
73+
}
74+
}
75+
}
76+
Start();
77+
}
78+
79+
private static void Start()
80+
{
81+
DateTime time1 = DateTime.Now;
82+
Console.WriteLine($"{time1.ToString()}:Started!");
83+
dictMyFileInfos = new Dictionary<string, MyFileInfo>();
84+
logPath = Path.Combine(logPath, time1.ToString("yyyyMMddHHmmss") + ".log");
85+
86+
foreach (string path in paths)
87+
{
88+
VisitPath(path);
89+
}
90+
DateTime time2 = DateTime.Now;
91+
Console.WriteLine($"{time2.ToString()}:Completed!");
92+
Console.WriteLine($"TotalCount:{dictMyFileInfos.Count}");
93+
Console.WriteLine("Result-------------------------------------------------------------------------------");
94+
int sameindex = 0;
95+
StringBuilder sb = new StringBuilder();
96+
foreach (var value in dictMyFileInfos.Values)
97+
{
98+
if (value.DuplicateFiles != null)
99+
{
100+
sameindex++;
101+
string s = sameindex + ":" + value.Name;
102+
foreach (var d in value.DuplicateFiles)
103+
{
104+
s += " And " + d.Name;
105+
}
106+
Console.WriteLine(s);
107+
sb.AppendLine(s);
108+
}
109+
}
110+
Console.WriteLine("Result-------------------------------------------------------------------------------");
111+
sb.AppendLine($"TotalDuplicateCounts:{sameindex}");
112+
sb.AppendLine($"TotalUsedSeconds:{(time2 - time1).TotalSeconds}");
113+
Console.WriteLine($"Done! File name is {logPath}");
114+
Console.WriteLine("Press any key to exit!");
115+
File.WriteAllText(logPath, sb.ToString());
116+
Console.Read();
117+
}
118+
private static void ShowLog(string message)
119+
{
120+
121+
}
122+
private static void VisitPath(string Path)
123+
{
124+
Console.WriteLine($"{DateTime.Now.ToString()}:Visiting {Path}");
125+
foreach (var file in Directory.GetFiles(Path))
126+
{
127+
var myfileinfo = GetMyFileInfo(file);
128+
if (dictMyFileInfos.ContainsKey(myfileinfo.Key))
129+
{
130+
if (dictMyFileInfos[myfileinfo.Key].DuplicateFiles == null)
131+
{
132+
dictMyFileInfos[myfileinfo.Key].DuplicateFiles = new List<MyFileInfo>();
133+
}
134+
dictMyFileInfos[myfileinfo.Key].DuplicateFiles.Add(myfileinfo);
135+
}
136+
else
137+
{
138+
dictMyFileInfos.Add(myfileinfo.Key, myfileinfo);
139+
}
140+
}
141+
142+
//visit the paths
143+
foreach (var dir in Directory.GetDirectories(Path))
144+
{
145+
VisitPath(dir);
146+
}
147+
}
148+
149+
private static MyFileInfo GetMyFileInfo(string FileName)
150+
{
151+
if (File.Exists(FileName))
152+
{
153+
return new MyFileInfo { Key= GetMD5WithFilePath (FileName),Name= FileName };
154+
}
155+
else
156+
{
157+
return null;
158+
}
159+
}
160+
161+
static MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
162+
static public string GetMD5WithFilePath(string filePath)
163+
{
164+
FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
165+
byte[] hash_byte = md5.ComputeHash(file);
166+
string str = System.BitConverter.ToString(hash_byte);
167+
str = str.Replace("-", "");
168+
return str;
169+
}
170+
}
171+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"DuplicateFileCheck": {
4+
"commandName": "Project",
5+
"commandLineArgs": "-p C:\\Github\\CSharpCodes C:\\Github\\JingShiZiJi -w true -l C:\\Temp"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)