Skip to content

TheMofaDe/DotNetHelper-IO

Repository files navigation

DotNetHelper-IO

DotNetHelper-IO is a simple easy to use thread safe library for handling all types of files & folders

|| DocumentationAPITutorials || Change Log • || View on Github||

Package Tests Code Coverage
Build Status Build Status codecov
Continous Integration Windows Linux MacOS
AppVeyor Build status
Azure Devops Build Status Build Status Build Status

Features

+ Auto Increment File Name
+ Auto Increment File Extension
+ Writing with async support
+ Reading with async support
+ Get file/folder file sizes by any size unit, example , bytes,kb,mb,gb etc..
+ Archive file support (.zip .rar .tar .7z .gzip)

Tutorial


Write Operation

Overloads for writing string,stream, or bytes exist
Async methods exist as well
var file = new FileObject($@"C:\Temp\MyTestFile.txt"); 

file.Write("Will create MyTestFile.txt with this content", FileOption.Append); 
file.Write("will ovewrite the file MyTestFile.txt with this text", FileOption.Overwrite);
file.Write("nothing will happen since file already exist", FileOption.DoNothingIfExist); 
var newFileName = file.Write("will create file MyTestFile.txt1 and this method returns file name", FileOption.IncrementFileExtensionIfExist); 
var newFileName2 = file.Write("will create file MyTestFile1.txt and this method returns file name ", FileOption.IncrementFileNameIfExist); 


Copying Operation

Async methods exist as well
var file = new FileObject($@"C:\Temp\MyTestFile.txt");
// Copies & Append file content to specified path
file.CopyTo("D:\\Temp\\MyTestFile.txt", FileOption.Append); 

// Copies file content and paste it to specified path and will overwrite if other file already exist
file.CopyTo("D:\\Temp\\MyTestFile.txt", FileOption.Overwrite);

// Copies file content to specified path only if it doesn't exist otherwise do nothing
file.CopyTo("D:\\Temp\\MyTestFile.txt", FileOption.DoNothingIfExist);

// Copy file content to specified path. If path already exist then create a new file with the file extension increment.
var newFileName = file.CopyTo("D:\\Temp\\MyTestFile.txt", FileOption.IncrementFileExtensionIfExist);

// Copy file content to specified path. If path already exist then create a new file with the file name increment.
var newFileName2 = file.CopyTo("D:\\Temp\\MyTestFile.txt", FileOption.IncrementFileNameIfExist); 


Archive Files (.zip .rar .gzip .7z .tar)

Read content of a archive file
var zipFile = new ZipFileObject($"C:\\Temp\\test.zip",ArchiveType.Zip);
using (var archive = zipFile.GetReadableArchive())
{
	foreach (var entry in archive.Entries)
	{
		var fileNameInZip = entry.Key;
		var fileContent = entry.OpenEntryStream();
	}
}
Add file to existing zip or automatically create a new zip with file in it
var zipFileObj = new ZipFileObject($"C:\\Temp\\test.zip", ArchiveType.Zip);
// overwrite file in zip if it already exist
zipFileObj.Add($"C:\\Temp\\TestFile.txt",FileOption.Overwrite);
// don't add to zip if already exist
zipFileObj.Add($"C:\\Temp\\TestFile.txt", FileOption.DoNothingIfExist);
// append to the same file in zip
zipFileObj.Add($"C:\\Temp\\TestFile.txt", FileOption.Append);



Documentation

For more information, please refer to the Officials Docs

Solution Template

badge

About

DotNetHelper-IO is a simple easy to use thread safe library for handling all types of files & folders

Resources

License

Stars

Watchers

Forks

Packages

No packages published