From c02e180aa8a19158ea75c94aef2eaa0cedd765d3 Mon Sep 17 00:00:00 2001 From: Scott Willeke Date: Sun, 22 May 2016 11:51:59 -0700 Subject: [PATCH] minor changes to consisntely use Remove rather than delete --- README.md | 14 ++++++++++++-- src/LessIO/FileSystem.cs | 15 +++++++++++++-- src/LessIO/Path.cs | 11 +---------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b22d03b..b61ce50 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,13 @@ This is a library for dealing with File I/O on .NET that overcomes some limitati It was created to factor out some of the file-system specific features that have built up in the [LessMSI project](https://github.com/activescott/lessmsi). + Goals ======== * Support File I/O operations on Windows that .NET's System.IO libraries fail to support such as long paths (those longer than 260 characters). * Provide a basis for platform independent file system access across both Windows and Unix-like systems such as Linux and Mac OSX, and potentially others (cloud file storage?). + Concepts & Usage ======== Two concepts are necessary to use the library `FileSystem` and `Path`. The static `FileSystem` class is a static class that contains all of the operations available on the `FileSystem`. Any operation that has a path argument, such as `FileSystem.CreateDirectory`, accepts paths as strongly typed `Path` objects rather than strings. For example, @@ -20,10 +22,11 @@ Having paths strongly typed rather than strings forces the caller to be more exp new Path(@"c:\src\\lessmsi") == new Path(@"c:\src\lessmsi") // true -`Path` has some handy shortcuts on it too such as Remove (delete) that calls back into the FileSystem to remove the file or directory at the current path: +`Path` has some handy shortcuts on it too such as Exists that calls back into the FileSystem to determine if the file or directory at the current path already exists. +These methods also provides some compatibility with existing code using System.IO.FileInfo or System.IO.DirectoryInfo so that in many cases you can replace usage of System.IO.FileInfo/DirectoryInfo with LessIO.Path. Path destDir = new Path(@"c:\src\lessmsi"); - destDir.Remove(); + Console.WriteLine(destDir.Exists); `Path` also offers some of the commonly used static methods on System.IO.Path to make the type relatively compatible with existing code using System.IO.Path. For example, `Combine` and `GetFileName` are available to make porting System.IO code easier: @@ -34,3 +37,10 @@ Having paths strongly typed rather than strings forces the caller to be more exp Platform Independence ======== The current implementation supports Win32 via the [Win32FileSystemStrategy.cs](https://github.com/activescott/LessIO/blob/master/src/LessIO/Strategies/Win32/Win32FileSystemStrategy.cs). However, adding support for another file system such as a Unixy file system could be done by implementing the ~10 methods on a class derived from [FileSystemStrategy](https://github.com/activescott/LessIO/blob/master/src/LessIO/Strategies/FileSystemStrategy.cs) and then updating the implementation of [FileSystem.LazyStrategy](https://github.com/activescott/LessIO/blob/master/src/LessIO/FileSystem.cs). + + +Contributing +======== +We accept pull requests! I think this is a sound basis, but obviously there are many improvements that could be made such as [improving platform independence by adding a new FileSystemStrategy](#platform-independence) or adding more static methods to [Path](https://github.com/activescott/LessIO/blob/master/src/LessIO/Path.cs) from System.IO.FileInfo/DirectoryInfo to make it easier to port System.IO code over to this library. There might also be some important methods missing on [FileSystem](https://github.com/activescott/LessIO/blob/master/src/LessIO/FileSystem.cs) as I just added the operations that [LessMSI](https://github.com/activescott/LessMSI) already uses which I imagine is fairly extensive but maybe not comprehensive. + +Please do make sure that existing tests pass and please add new ones for the new features you write. diff --git a/src/LessIO/FileSystem.cs b/src/LessIO/FileSystem.cs index 8d748dc..2509fc2 100644 --- a/src/LessIO/FileSystem.cs +++ b/src/LessIO/FileSystem.cs @@ -61,7 +61,7 @@ public static void CreateDirectory(Path path) } /// - /// Deletes an existing empty directory. + /// Removes/deletes an existing empty directory. /// See https://msdn.microsoft.com/en-us/library/windows/desktop/aa365488%28v=vs.85%29.aspx /// /// @@ -71,7 +71,7 @@ public static void RemoveDirectory(Path path) } /// - /// Deletes an existing empty directory. + /// Removes/deletes an existing directory. /// See https://msdn.microsoft.com/en-us/library/windows/desktop/aa365488%28v=vs.85%29.aspx /// /// The path to the directory to remove. @@ -97,6 +97,17 @@ public static void RemoveFile(Path path, bool forcefully) Strategy.RemoveFile(path, forcefully); } + /// + /// Removes/deletes an existing file. + /// To remove a directory see . + /// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363915%28v=vs.85%29.aspx + /// + /// The file to remove. + public static void RemoveFile(Path path) + { + Strategy.RemoveFile(path, false); + } + /// /// Copies the specified existing file to a new location. /// Will throw an exception if the destination file already exists. diff --git a/src/LessIO/Path.cs b/src/LessIO/Path.cs index 97d02f2..39f23be 100644 --- a/src/LessIO/Path.cs +++ b/src/LessIO/Path.cs @@ -354,6 +354,7 @@ public Path Parent } /// + /// Indicates if the file or directory at the specified path exists. /// For code compatibility with . /// public bool Exists @@ -381,16 +382,6 @@ public bool IsPathRooted } } - - - /// - /// For code compatibility with - /// - public void Delete() - { - FileSystem.RemoveFile(this, false); - } - /// /// For code compatibility with ///