-
Notifications
You must be signed in to change notification settings - Fork 0
/
INetProFileProvider.cs
302 lines (269 loc) · 13.8 KB
/
INetProFileProvider.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
using Microsoft.Extensions.FileProviders;
using System;
using System.Collections.Generic;
using System.Text;
namespace NetPro.TypeFinder
{
/// <summary>
/// 文件操作抽象类
/// </summary>
public interface INetProFileProvider : IFileProvider
{
/// <summary>
/// 文件路径合并
/// </summary>
/// <param name="paths">An array of parts of the path</param>
/// <returns>The combined paths</returns>
string Combine(params string[] paths);
/// <summary>
/// 创建一个目录(文件夹)
/// </summary>
/// <param name="path">文件夹路径</param>
void CreateDirectory(string path);
/// <summary>
///新增一个文件.如果文件已存在则跳过
/// </summary>
/// <param name="path">文件完整路径</param>
void CreateFile(string path);
/// <summary>
/// 删除目录.
/// </summary>
/// <param name="path">Directory path</param>
void DeleteDirectory(string path);
/// <summary>
/// 删除文件
/// </summary>
/// <param name="filePath">The name of the file to be deleted. Wildcard characters are not supported</param>
void DeleteFile(string filePath);
/// <summary>
/// Determines whether the given path refers to an existing directory on disk
/// </summary>
/// <param name="path">The path to test</param>
/// <returns>
/// true if path refers to an existing directory; false if the directory does not exist or an error occurs when
/// trying to determine if the specified file exists
/// </returns>
bool DirectoryExists(string path);
/// <summary>
/// 文件夹移动
/// </summary>
/// <param name="sourceDirName">原目录路径</param>
/// <param name="destDirName">
/// The path to the new location for sourceDirName. If sourceDirName is a file, then destDirName
/// must also be a file name
/// </param>
void DirectoryMove(string sourceDirName, string destDirName);
/// <summary>
/// Returns an enumerable collection of file names that match a search pattern in
/// a specified path, and optionally searches subdirectories.
/// </summary>
/// <param name="directoryPath">The path to the directory to search</param>
/// <param name="searchPattern">
/// The search string to match against the names of files in path. This parameter
/// can contain a combination of valid literal path and wildcard (* and ?) characters
/// , but doesn't support regular expressions.
/// </param>
/// <param name="topDirectoryOnly">
/// Specifies whether to search the current directory, or the current directory and all
/// subdirectories
/// </param>
/// <returns>
/// An enumerable collection of the full names (including paths) for the files in
/// the directory specified by path and that match the specified search pattern
/// </returns>
IEnumerable<string> EnumerateFiles(string directoryPath, string searchPattern, bool topDirectoryOnly = true);
/// <summary>
/// 文件复制
/// </summary>
/// <param name="sourceFileName">The file to copy</param>
/// <param name="destFileName">The name of the destination file. This cannot be a directory</param>
/// <param name="overwrite">是否覆盖,如果文件重复</param>
void FileCopy(string sourceFileName, string destFileName, bool overwrite = false);
/// <summary>
/// Determines whether the specified file exists
/// </summary>
/// <param name="filePath">The file to check</param>
/// <returns>
/// True if the caller has the required permissions and path contains the name of an existing file; otherwise,
/// false.
/// </returns>
bool FileExists(string filePath);
/// <summary>
/// Gets the length of the file in bytes, or -1 for a directory or non-existing files
/// </summary>
/// <param name="path">File path</param>
/// <returns>The length of the file</returns>
long FileLength(string path);
/// <summary>
/// Moves a specified file to a new location, providing the option to specify a new file name
/// </summary>
/// <param name="sourceFileName">The name of the file to move. Can include a relative or absolute path</param>
/// <param name="destFileName">The new path and name for the file</param>
void FileMove(string sourceFileName, string destFileName);
/// <summary>
/// Returns the absolute path to the directory
/// </summary>
/// <param name="paths">An array of parts of the path</param>
/// <returns>The absolute path to the directory</returns>
string GetAbsolutePath(params string[] paths);
/// <summary>
/// 文件(夹)创建时间
/// </summary>
/// <param name="path">The file or directory for which to obtain creation date and time information</param>
/// <returns>
/// A System.DateTime structure set to the creation date and time for the specified file or directory. This value
/// is expressed in local time
/// </returns>
DateTime GetCreationTime(string path);
/// <summary>
/// Returns the names of the subdirectories (including their paths) that match the
/// specified search pattern in the specified directory
/// </summary>
/// <param name="path">The path to the directory to search</param>
/// <param name="searchPattern">
/// The search string to match against the names of subdirectories in path. This
/// parameter can contain a combination of valid literal and wildcard characters
/// , but doesn't support regular expressions.
/// </param>
/// <param name="topDirectoryOnly">
/// Specifies whether to search the current directory, or the current directory and all
/// subdirectories
/// </param>
/// <returns>
/// An array of the full names (including paths) of the subdirectories that match
/// the specified criteria, or an empty array if no directories are found
/// </returns>
string[] GetDirectories(string path, string searchPattern = "", bool topDirectoryOnly = true);
/// <summary>
/// Returns the directory information for the specified path string
/// </summary>
/// <param name="path">The path of a file or directory</param>
/// <returns>
/// Directory information for path, or null if path denotes a root directory or is null. Returns
/// System.String.Empty if path does not contain directory information
/// </returns>
string GetDirectoryName(string path);
/// <summary>
/// Returns the directory name only for the specified path string
/// </summary>
/// <param name="path">The path of directory</param>
/// <returns>The directory name</returns>
string GetDirectoryNameOnly(string path);
/// <summary>
/// Returns the extension of the specified path string
/// </summary>
/// <param name="filePath">The path string from which to get the extension</param>
/// <returns>The extension of the specified path (including the period ".")</returns>
string GetFileExtension(string filePath);
/// <summary>
/// Returns the file name and extension of the specified path string
/// </summary>
/// <param name="path">The path string from which to obtain the file name and extension</param>
/// <returns>The characters after the last directory character in path</returns>
string GetFileName(string path);
/// <summary>
/// Returns the file name of the specified path string without the extension
/// </summary>
/// <param name="filePath">The path of the file</param>
/// <returns>The file name, minus the last period (.) and all characters following it</returns>
string GetFileNameWithoutExtension(string filePath);
/// <summary>
/// Returns the names of files (including their paths) that match the specified search
/// pattern in the specified directory, using a value to determine whether to search subdirectories.
/// </summary>
/// <param name="directoryPath">The path to the directory to search</param>
/// <param name="searchPattern">
/// The search string to match against the names of files in path. This parameter
/// can contain a combination of valid literal path and wildcard (* and ?) characters
/// , but doesn't support regular expressions.
/// </param>
/// <param name="topDirectoryOnly">
/// Specifies whether to search the current directory, or the current directory and all
/// subdirectories
/// </param>
/// <returns>
/// An array of the full names (including paths) for the files in the specified directory
/// that match the specified search pattern, or an empty array if no files are found.
/// </returns>
string[] GetFiles(string directoryPath, string searchPattern = "", bool topDirectoryOnly = true);
/// <summary>
/// Returns the date and time the specified file or directory was last accessed
/// </summary>
/// <param name="path">The file or directory for which to obtain access date and time information</param>
/// <returns>A System.DateTime structure set to the date and time that the specified file</returns>
DateTime GetLastAccessTime(string path);
/// <summary>
///文件(夹)最后修改时间
/// </summary>
/// <param name="path">The file or directory for which to obtain write date and time information</param>
/// <returns>
/// A System.DateTime structure set to the date and time that the specified file or directory was last written to.
/// This value is expressed in local time
/// </returns>
DateTime GetLastWriteTime(string path);
/// <summary>
/// Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last
/// written to
/// </summary>
/// <param name="path">The file or directory for which to obtain write date and time information</param>
/// <returns>
/// A System.DateTime structure set to the date and time that the specified file or directory was last written to.
/// This value is expressed in UTC time
/// </returns>
DateTime GetLastWriteTimeUtc(string path);
/// <summary>
/// Retrieves the parent directory of the specified path
/// </summary>
/// <param name="directoryPath">The path for which to retrieve the parent directory</param>
/// <returns>The parent directory, or null if path is the root directory, including the root of a UNC server or share name</returns>
string GetParentDirectory(string directoryPath);
/// <summary>
/// 路径是否为目录
/// </summary>
/// <param name="path">Path for check</param>
/// <returns>True, if the path is a directory, otherwise false</returns>
bool IsDirectory(string path);
/// <summary>
/// Maps a virtual path to a physical disk path.
/// </summary>
/// <param name="path">The path to map. E.g. "~/bin"</param>
/// <returns>The physical path. E.g. "c:\inetpub\wwwroot\bin"</returns>
string MapPath(string path);
/// <summary>
/// Reads the contents of the file into a byte array
/// </summary>
/// <param name="filePath">The file for reading</param>
/// <returns>A byte array containing the contents of the file</returns>
byte[] ReadAllBytes(string filePath);
/// <summary>
/// Opens a file, reads all lines of the file with the specified encoding, and then closes the file.
/// </summary>
/// <param name="path">The file to open for reading</param>
/// <param name="encoding">The encoding applied to the contents of the file</param>
/// <returns>A string containing all lines of the file</returns>
string ReadAllText(string path, Encoding encoding);
/// <summary>
/// Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to
/// </summary>
/// <param name="path">The file for which to set the date and time information</param>
/// <param name="lastWriteTimeUtc">
/// A System.DateTime containing the value to set for the last write date and time of path.
/// This value is expressed in UTC time
/// </param>
void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc);
/// <summary>
/// Writes the specified byte array to the file
/// </summary>
/// <param name="filePath">The file to write to</param>
/// <param name="bytes">The bytes to write to the file</param>
void WriteAllBytes(string filePath, byte[] bytes);
/// <summary>
/// Creates a new file, writes the specified string to the file using the specified encoding,
/// and then closes the file. If the target file already exists, it is overwritten.
/// </summary>
/// <param name="path">The file to write to</param>
/// <param name="contents">The string to write to the file</param>
/// <param name="encoding">The encoding to apply to the string</param>
void WriteAllText(string path, string contents, Encoding encoding);
}
}