Skip to content

conesoft/nuget-files

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conesoft.Files

publish to nuget

NuGet version (Conesoft.Files) https://www.nuget.org/packages/Conesoft.Files/

tiny example

adapted from realworld use

var logfile = Directory.From("SomeRoot") / "Scheduler" / Filename.From(DateTime.Today.ToShortDateString(), "md");

await logfile.AppendText($"- **{task.GetType().Name}** *executed* ");

instead of

var logPath = System.IO.Path.Combine("SomeRoot", "Scheduler", $"{DateTime.Today.ToShortDateString()}.md");
await System.IO.File.AppendAllTextAsync(logPath, $"- **{task.GetType().Name}** *executed* ");

reading/writing objects

var data = await File.From("some\path.json").ReadFromJson<SomeType>();

File.From("some\other path.json").WriteAsJson(data);

temporary directories

{
    using var temp = Directory.Common.Temporary();
    
    await (temp / Filename.From("some temporary", "tmp")).WriteBytes(somebytes);
    
    // temporary directory gets deleted when out of scope
}

watching a folder

void PrettyPrint(string title, File[] files)
{
    if(files.Length > 0)
    {
        Console.WriteLine($"{title} ({files.Length})");
        foreach(var file in files)
        {
            Console.WriteLine(file);
        }
        Console.WriteLine();
    }
}

await foreach(var files in Directory.From("some\path"))
{
    PrettyPrint("ALL FILES", files.All);
    PrettyPrint("ADDED FILES", files.Added);
    PrettyPrint("CHANGED FILES", files.Changed);
    PrettyPrint("DELETED FILES", files.Deleted);
}

About

tiny wrapper around System.IO to make life easier

Topics

Resources

License

Stars

Watchers

Forks

Languages