forked from JanKallman/EPPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
56 lines (54 loc) · 1.57 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace EPPlusSamples
{
public class Utils
{
static DirectoryInfo _outputDir = null;
public static DirectoryInfo OutputDir
{
get
{
return _outputDir;
}
set
{
_outputDir = value;
if (!_outputDir.Exists)
{
_outputDir.Create();
}
}
}
public static FileInfo GetFileInfo(string file, bool deleteIfExists = true)
{
var fi = new FileInfo(OutputDir.FullName + Path.DirectorySeparatorChar + file);
if (deleteIfExists && fi.Exists)
{
fi.Delete(); // ensures we create a new workbook
}
return fi;
}
public static FileInfo GetFileInfo(DirectoryInfo altOutputDir, string file, bool deleteIfExists = true)
{
var fi = new FileInfo(altOutputDir.FullName + Path.DirectorySeparatorChar + file);
if (deleteIfExists && fi.Exists)
{
fi.Delete(); // ensures we create a new workbook
}
return fi;
}
internal static DirectoryInfo GetDirectoryInfo(string directory)
{
var di = new DirectoryInfo(_outputDir.FullName + Path.DirectorySeparatorChar + directory);
if (!di.Exists)
{
di.Create();
}
return di;
}
}
}