-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileSystemCompare.cs
78 lines (67 loc) · 2.2 KB
/
FileSystemCompare.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace FileExplorer
{
class hartsuul : IComparer
{
public enum SORTORDER { DESC, ASC };
public int columnIndex = 0;
public SORTORDER sortOrder = SORTORDER.ASC;
public int Compare(object x, object y)
{
FileSystemInfo firstFile = ((ListViewItem)x).Tag as FileSystemInfo;
FileSystemInfo secondFile = ((ListViewItem)y).Tag as FileSystemInfo;
if (firstFile == null || secondFile == null)
{
return 0;
}
if (firstFile is DirectoryInfo && secondFile is FileInfo)
{
return -1;
}
if (firstFile is FileInfo && secondFile is DirectoryInfo)
{
return 1;
}
int result = 0;
switch (columnIndex)
{
case 0:
result = firstFile.Name.CompareTo(secondFile.Name);
break;
case 1:
if (firstFile is FileInfo && secondFile is FileInfo)
{
result = ((FileInfo)firstFile).Length.CompareTo(((FileInfo)secondFile).Length);
}
else
{
return 0;
}
break;
case 2:
result = firstFile.CreationTime.CompareTo(secondFile.CreationTime);
break;
case 3:
result = firstFile.LastWriteTime.CompareTo(secondFile.LastWriteTime);
break;
default:
return 0;
}
if (sortOrder == SORTORDER.ASC)
{
return result;
}
else
{
return (-1) * result;
}
}
}
}