Line | |
---|
1 | using System.IO;
|
---|
2 | using System.Linq;
|
---|
3 |
|
---|
4 | namespace Common
|
---|
5 | {
|
---|
6 | public static class FileExt
|
---|
7 | {
|
---|
8 | public static void WriteAllBytesUpdate(string fileName, byte[] content)
|
---|
9 | {
|
---|
10 | if (File.Exists(fileName))
|
---|
11 | {
|
---|
12 | byte[] previousContent = File.ReadAllBytes(fileName);
|
---|
13 | if (!previousContent.SequenceEqual(content)) File.WriteAllBytes(fileName, content);
|
---|
14 | } else File.WriteAllBytes(fileName, content);
|
---|
15 | }
|
---|
16 |
|
---|
17 | public static void WriteAllTextUpdate(string fileName, string content)
|
---|
18 | {
|
---|
19 | if (File.Exists(fileName))
|
---|
20 | {
|
---|
21 | string previousContent = File.ReadAllText(fileName);
|
---|
22 | if (previousContent != content) File.WriteAllText(fileName, content);
|
---|
23 | } else File.WriteAllText(fileName, content);
|
---|
24 | }
|
---|
25 |
|
---|
26 | public static string GetExactPathName(string pathName)
|
---|
27 | {
|
---|
28 | if (!(File.Exists(pathName) || Directory.Exists(pathName)))
|
---|
29 | return pathName;
|
---|
30 |
|
---|
31 | var di = new DirectoryInfo(pathName);
|
---|
32 |
|
---|
33 | if (di.Parent != null)
|
---|
34 | {
|
---|
35 | return Path.Combine(
|
---|
36 | GetExactPathName(di.Parent.FullName),
|
---|
37 | di.Parent.GetFileSystemInfos(di.Name)[0].Name);
|
---|
38 | }
|
---|
39 | else
|
---|
40 | {
|
---|
41 | return di.FullName.ToUpper();
|
---|
42 | }
|
---|
43 | }
|
---|
44 | }
|
---|
45 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.