-
Notifications
You must be signed in to change notification settings - Fork 331
/
Copy pathIFileHelper.cs
163 lines (142 loc) · 5.76 KB
/
IFileHelper.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using System.IO;
namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;
/// <summary>
/// The FileHelper interface.
/// </summary>
public interface IFileHelper
{
/// <summary>
/// Creates a directory.
/// </summary>
/// <param name="path">Path of the directory.</param>
/// <returns><see cref="DirectoryInfo"/> for the created directory.</returns>
DirectoryInfo CreateDirectory(string path);
/// <summary>
/// Gets the current directory
/// </summary>
/// <returns>Current directory</returns>
string GetCurrentDirectory();
/// <summary>
/// Exists utility to check if file exists (case sensitive).
/// </summary>
/// <param name="path"> The path of file. </param>
/// <returns>True if file exists <see cref="bool"/>.</returns>
bool Exists([NotNullWhen(true)] string? path);
/// <summary>
/// Exists utility to check if directory exists (case sensitive).
/// </summary>
/// <param name="path"> The path of file. </param>
/// <returns>True if directory exists <see cref="bool"/>.</returns>
bool DirectoryExists([NotNullWhen(true)] string? path);
/// <summary>
/// Gets a stream for the file.
/// </summary>
/// <param name="filePath">Path to the file.</param>
/// <param name="mode"><see cref="FileMode"/> for file operations.</param>
/// <param name="access"><see cref="FileAccess"/> for file operations.</param>
/// <returns>A <see cref="Stream"/> that supports read/write on the file.</returns>
Stream GetStream(string filePath, FileMode mode, FileAccess access = FileAccess.ReadWrite);
/// <summary>
/// Gets a stream for the file.
/// </summary>
/// <param name="filePath">Path to the file.</param>
/// <param name="mode"><see cref="FileMode"/> for file operations.</param>
/// <param name="access"><see cref="FileAccess"/> for file operations.</param>
/// <param name="share"><see cref="FileShare"/> for file operations.</param>
/// <returns>A <see cref="Stream"/> that supports read/write on the file.</returns>
Stream GetStream(string filePath, FileMode mode, FileAccess access, FileShare share);
/// <summary>
/// Enumerates files which match a pattern (case insensitive) in a directory.
/// </summary>
/// <param name="directory">Parent directory to search.</param>
/// <param name="searchOption"><see cref="SearchOption"/> for directory.</param>
/// <param name="endsWithSearchPatterns">Patterns used to select files using String.EndsWith</param>
/// <returns>List of files matching the pattern.</returns>
IEnumerable<string> EnumerateFiles(string directory, SearchOption searchOption, params string[]? endsWithSearchPatterns);
/// <summary>
/// Gets attributes of a file.
/// </summary>
/// <param name="path">Full path of the file.</param>
/// <returns>Attributes of the file.</returns>
FileAttributes GetFileAttributes(string path);
/// <summary>
/// Gets the version information of the file.
/// </summary>
/// <param name="path">Full path to the file.</param>
/// <returns>File Version information of the file.</returns>
Version GetFileVersion(string path);
/// <summary>
/// Copy a file in the file system.
/// </summary>
/// <param name="sourcePath">Full path of the file.</param>
/// <param name="destinationPath">Target path for the file.</param>
void CopyFile(string sourcePath, string destinationPath);
/// <summary>
/// Moves a file in the file system.
/// </summary>
/// <param name="sourcePath">Full path of the file.</param>
/// <param name="destinationPath">Target path for the file.</param>
void MoveFile(string sourcePath, string destinationPath);
/// <summary>
/// The write all text to file.
/// </summary>
/// <param name="filePath">
/// The file Path.
/// </param>
/// <param name="content">
/// The content.
/// </param>
void WriteAllTextToFile(string filePath, string content);
/// <summary>
/// Gets full path if relative path is specified.
/// </summary>
/// <param name="path">
/// The path.
/// </param>
/// <returns>
/// Full path.
/// </returns>
string GetFullPath(string path);
/// <summary>
/// Helper for deleting a directory. It deletes the directory only if its empty.
/// </summary>
/// <param name="directoryPath">
/// The directory path.
/// </param>
void DeleteEmptyDirectroy(string directoryPath);
/// <summary>
/// Helper for deleting a directory.
/// </summary>
/// <param name="directoryPath">
/// The directory path.
/// </param>
/// <param name="recursive">If we should delete recursively.</param>
void DeleteDirectory(string directoryPath, bool recursive);
/// <summary>
/// Gets all files in directory based on search pattern
/// </summary>
/// <param name="path">Directory Path</param>
/// <param name="searchPattern">Search pattern</param>
/// <param name="searchOption">Search option</param>
/// <returns>string[]</returns>
string[] GetFiles(string path, string searchPattern, SearchOption searchOption);
/// <summary>
/// Deletes the specified file
/// </summary>
/// <param name="path"></param>
void Delete(string path);
/// <summary>
/// Get temporary file path
/// </summary>
public string GetTempPath();
/// <summary>
/// Get file length
/// </summary>
/// <param name="path"></param>
public long GetFileLength(string path);
}