Skip to content

Commit 0e7930e

Browse files
committed
Abstract implementation of System.IO.Path
1 parent 0d1143c commit 0e7930e

6 files changed

Lines changed: 766 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ Abstraction for the .Net Filesystem classes
77

88
Wrappers for some common classes from System.IO Namespace to create a layer of abstraction
99

10-
Current implementaitons of System.IO
10+
Current abstractions of System.IO
1111
* Directory
1212
* File
13+
* Path
1314

1415
## Usage in code
1516
Instead of using the Namespace System.IO include the Namespace Abstract.FileSystem to use Directory or File.

src/Abstract.FileSystem/FileService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace Abstract.FileSystem
77
{
8+
/// <summary>
9+
/// Wrapper for System.IO.File
10+
/// </summary>
811
public partial class FileService : IFileService
912
{
1013
/// <summary>
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
namespace Abstract.FileSystem
2+
{
3+
/// <summary>
4+
/// Abstract service for System.IO.Path
5+
/// </summary>
6+
public interface IPathService
7+
{
8+
/// <summary>
9+
/// Changes the extension of a path string.
10+
/// </summary>
11+
/// <param name="path">The path information to modify. The path cannot contain any of the characters defined in System.IO.Path.GetInvalidPathChars.</param>
12+
/// <param name="extension">The new extension (with or without a leading period). Specify null to remove an existing extension from path.</param>
13+
/// <returns>The modified path information. On Windows-based desktop platforms, if path is
14+
/// null or an empty string (""), the path information is returned unmodified. If
15+
/// extension is null, the returned string contains the specified path with its extension
16+
/// removed. If path has no extension, and extension is not null, the returned path
17+
/// string contains extension appended to the end of path.
18+
/// </returns>
19+
string ChangeExtension(string path, string extension);
20+
21+
/// <summary>
22+
/// Combines two strings into a path.
23+
/// </summary>
24+
/// <param name="path1">The first path to combine.</param>
25+
/// <param name="path2">The second path to combine.</param>
26+
/// <returns>The combined paths. If one of the specified paths is a zero-length string, this
27+
/// method returns the other path. If path2 contains an absolute path, this method
28+
/// returns path2.</returns>
29+
string Combine(string path1, string path2);
30+
31+
/// <summary>
32+
/// Combines three strings into a path.
33+
/// </summary>
34+
/// <param name="path1">The first path to combine.</param>
35+
/// <param name="path2">The second path to combine.</param>
36+
/// <param name="path3">The third path to combine.</param>
37+
/// <returns>The combined paths.</returns>
38+
string Combine(string path1, string path2, string path3);
39+
40+
/// <summary>
41+
/// Combines four strings into a path.
42+
/// </summary>
43+
/// <param name="path1">The first path to combine.</param>
44+
/// <param name="path2">The second path to combine.</param>
45+
/// <param name="path3">The third path to combine.</param>
46+
/// <param name="path4">The fourth path to combine.</param>
47+
/// <returns>The combined paths.</returns>
48+
string Combine(string path1, string path2, string path3, string path4);
49+
50+
/// <summary>
51+
/// Combines an array of strings into a path.
52+
/// </summary>
53+
/// <param name="paths">An array of parts of the path.</param>
54+
/// <returns>The combined paths.</returns>
55+
string Combine(params string[] paths);
56+
57+
/// <summary>
58+
/// Returns the directory information for the specified path string.
59+
/// </summary>
60+
/// <param name="path">The path of a file or directory.</param>
61+
/// <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>
62+
string GetDirectoryName(string path);
63+
64+
/// <summary>
65+
/// Returns the extension of the specified path string.
66+
/// </summary>
67+
/// <param name="path">The path string from which to get the extension.</param>
68+
/// <returns>The extension of the specified path (including the period "."), or null, or System.String.Empty.
69+
/// If path is null, System.IO.Path.GetExtension(System.String) returns null. If
70+
/// path does not have extension information, System.IO.Path.GetExtension(System.String)
71+
/// returns System.String.Empty.</returns>
72+
string GetExtension(string path);
73+
74+
/// <summary>
75+
/// Returns the file name and extension of the specified path string.
76+
/// </summary>
77+
/// <param name="path">The path string from which to obtain the file name and extension.</param>
78+
/// <returns>The characters after the last directory character in path. If the last character
79+
/// of path is a directory or volume separator character, this method returns System.String.Empty.
80+
/// If path is null, this method returns null.</returns>
81+
string GetFileName(string path);
82+
83+
/// <summary>
84+
/// Returns the file name of the specified path string without the extension.
85+
/// </summary>
86+
/// <param name="path">The path of the file.</param>
87+
/// <returns>The string returned by System.IO.Path.GetFileName(System.String), minus the last period (.) and all characters following it.</returns>
88+
string GetFileNameWithoutExtension(string path);
89+
90+
/// <summary>
91+
/// Returns the absolute path for the specified path string.
92+
/// </summary>
93+
/// <param name="path">The file or directory for which to obtain absolute path information.</param>
94+
/// <returns>The fully qualified location of path, such as "C:\MyFile.txt".</returns>
95+
string GetFullPath(string path);
96+
97+
/// <summary>
98+
/// Gets an array containing the characters that are not allowed in file names.
99+
/// </summary>
100+
/// <returns>An array containing the characters that are not allowed in file names.</returns>
101+
char[] GetInvalidFileNameChars();
102+
103+
/// <summary>
104+
/// Gets an array containing the characters that are not allowed in path names.
105+
/// </summary>
106+
/// <returns>An array containing the characters that are not allowed in path names.</returns>
107+
char[] GetInvalidPathChars();
108+
109+
/// <summary>
110+
/// Gets the root directory information of the specified path.
111+
/// </summary>
112+
/// <param name="path">The path from which to obtain root directory information.</param>
113+
/// <returns>The root directory of path, such as "C:\", or null if path is null, or an empty string if path does not contain root directory information.</returns>
114+
string GetPathRoot(string path);
115+
116+
/// <summary>
117+
/// Returns a random folder name or file name.
118+
/// </summary>
119+
/// <returns>A random folder name or file name.</returns>
120+
string GetRandomFileName();
121+
122+
/// <summary>
123+
/// Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.
124+
/// </summary>
125+
/// <returns>The full path of the temporary file.</returns>
126+
string GetTempFileName();
127+
128+
/// <summary>
129+
/// Returns the path of the current user's temporary folder.
130+
/// </summary>
131+
/// <returns>The path to the temporary folder, ending with a backslash.</returns>
132+
string GetTempPath();
133+
134+
/// <summary>
135+
/// Determines whether a path includes a file name extension.
136+
/// </summary>
137+
/// <param name="path">The path to search for an extension.</param>
138+
/// <returns>true if the characters that follow the last directory separator (\\ or /) or
139+
/// volume separator (:) in the path include a period (.) followed by one or more
140+
/// characters; otherwise, false.</returns>
141+
bool HasExtension(string path);
142+
143+
/// <summary>
144+
/// Gets a value indicating whether the specified path string contains a root.
145+
/// </summary>
146+
/// <param name="path">The path to test.</param>
147+
/// <returns>true if path contains a root; otherwise, false.</returns>
148+
bool IsPathRooted(string path);
149+
}
150+
}

0 commit comments

Comments
 (0)