-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUtils.cs
executable file
·71 lines (61 loc) · 2.23 KB
/
Utils.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
namespace Fr.Zhou.S3
{
class Utils
{
public static ArrayList AlFiles = new ArrayList();
public static ArrayList AlDirectories = new ArrayList();
public static void ListDirectory(string StrBaseDir)
{
DirectoryInfo Di = new DirectoryInfo(StrBaseDir);
DirectoryInfo[] DiS = Di.GetDirectories();
FileInfo[] FiDir = Di.GetFiles();
for (int i = 0; i < FiDir.Length; i++)
AlFiles.Add(FiDir[i].FullName);
for (int i = 0; i < DiS.Length; i++)
{
AlDirectories.Add(DiS[i].FullName);
ListDirectory(DiS[i].FullName);
}
}
public static bool IsDirectory(string path)
{
if (path.EndsWith("/"))
return true;
else
return false;
}
public static string GetKeyByPath(string FilePath, string BasePath)
{
FileInfo FiLocal = new FileInfo(FilePath);
FileInfo FiBase = new FileInfo(BasePath + "\\");
string FiLocalDir = FiLocal.DirectoryName;
string FiBaseDir = FiBase.DirectoryName;
string S3Key = FiLocal.FullName.Substring(FiBaseDir.Length + 1);
S3Key = S3Key.Replace("\\", "/");
return S3Key;
}
public static string Md5(string path)
{
try
{
FileStream get_file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
System.Security.Cryptography.MD5CryptoServiceProvider get_md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hash_byte = get_md5.ComputeHash(get_file);
string resule = System.BitConverter.ToString(hash_byte);
resule = resule.Replace("-", "");
get_file.Close();
return resule;
}
catch (Exception e)
{
return e.ToString();
}
}
}
}