Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/diev/aplib-pathinfo.cs
C# PathInfo.cs module encapsulates a file system path (not shell path!) and wraps Path, File, Directory static class methods from System.IO namespace, provides FileInfo DirectoryInfo objects, has additional properties and methods.
https://github.com/diev/aplib-pathinfo.cs
Last synced: about 2 months ago
JSON representation
C# PathInfo.cs module encapsulates a file system path (not shell path!) and wraps Path, File, Directory static class methods from System.IO namespace, provides FileInfo DirectoryInfo objects, has additional properties and methods.
- Host: GitHub
- URL: https://github.com/diev/aplib-pathinfo.cs
- Owner: diev
- Created: 2017-01-02T19:54:19.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2013-06-23T17:48:43.000Z (over 11 years ago)
- Last Synced: 2023-03-04T23:42:19.596Z (almost 2 years ago)
- Language: C#
- Size: 215 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
PathInfo.cs
===========C# PathInfo.cs module encapsulates a file system path (not shell path!) and wraps Path, File, Directory static class methods from System.IO namespace, provides FileInfo DirectoryInfo objects, has additional properties and methods.
This is a simple module distributed under MIT license, you can use in any project and write code in a little more functional style.Nearest projects
-----------
FluentPath http://fluentpath.codeplex.com/
NDepend.Helpers(?) https://github.com/curasystems/externals/tree/master/libs/NDepend.Helpers.FileDirectoryPath.1.0Features
-----------PathInfo
- Creating, combining, comparing, enumerating file system paths.
- Special folders, name generators, all file and directory operations.
- / * ^ & OperatorsPathList
- + - Operators
- Bulk file operationsSee examples in the unit test, and in the folder Examples
```csharp
// CreatingPathInfo some_path = Path.GetTempPath(); // by assigning the path
some_path = new PathInfo(@"C:\TEMP", "subdir", "filename.txt"); // from segments
some_path = PathInfo.Create(@"C:\TEMP\subdir", "filename.txt"); // static factory
some_path = new PathInfo(@"C:\TEMP\subdir\filename.txt"); // from full path// Special folders
some_path = PathInfo.APPLICATION_DATA_LOCAL / "some app folder";
var temp_path = PathInfo.TEMP;
PathInfo app_local = Environment.SpecialFolder.LocalApplicationData; // by assigning the Environment.SpecialFolder value
app_local = (PathInfo)Environment.SpecialFolder.LocalApplicationData / "some app folder";// Combining
some_path = some_path.Parent.Combine("some path segment", "filename.txt"); // Combine()
some_path = some_path.Parent / "some path segment" / "filename.txt"; // "/" Operator// Enumerating
var tmp_files = temp_path.Files("*.tmp"); // Enumerate .tmp files in temp directory
var tmp_dirs = temp_path.Directories("*.tmp");
tmp_files = temp_path & "*.tmp"; // eq & Operator enumerate filesvar regex = new Regex(@"\\[0-9]*\.tmp$");
var tmp_digital = temp_path & (path => { return regex.IsMatch(path); }); // Enumerate by match comparer
var hidden_dirs = temp_path.Directories().Where(dir => dir.Attributes.HasFlag(FileAttributes.Hidden)); // Enumerate hidden directories in temp directory// Enumerable
var selected = tmp_files .Where(path => path.Name.StartsWith("Z"));
selected = tmp_files .WhereFileName("^Z.*$"); // Regex mathing// PathList, set operations
tmp_digital += temp_path.Files().WhereFileName(@"[0-9]*\.exe");
tmp_digital -= "Z.*";
tmp_digital -= (path => path.Name.StartsWith("Z"));
var dirs = tmp_dirs + hidden_dirs;// Bulk
try
{
// files renaming exampletmp_files .Bulk(file => { file.Rename(file.FileName + ".bak"); });
}
catch (BulkException e)
{
foreach(var renamed in e.Successful)
Console.WriteLine(string.Format("renaming succesul, new file name: {0}", renamed.FileName));foreach(var fail in e.Failed)
Console.WriteLine(string.Format("renaming failed {0}", fail.Object));
}try
{
// a b c hidden directories creation examplenew PathList(new[] { temp_path / "a", temp_path / "b", temp_path / "c" })
.Bulk(path => { path.DirectoryCreate().DirectoryInfo.Attributes |= FileAttributes.Hidden; });}
catch (BulkException e)
{
foreach (var fail in e.Failed)
Console.WriteLine(string.Format("failed ", fail.Object));
}```