Package for C# that allows to work with files: create, delete, write, read, get files/directories, create special JSONs and work with them.
- Use to create files and directories, write and read files, get files/directories in directories:
public static class WorkerFiles
public static void CreateFile(FileInfo file)
Example
string path = "AbsolutePathToFile";
FileInfo someFile = new FileInfo(path);
WorkerFiles.CreateFile(someFile);
public static void DeleteFile(FileInfo file)
Example
string path = "AbsolutePathToFile";
FileInfo someFile = new FileInfo(path);
WorkerFiles.DeleteFile(someFile);
public static void CreateDir(string path)
Example
string path = "AbsolutePathToDirectory";
FileInfo someFile = new FileInfo(path);
WorkerFiles.CreateDir(someFile);
public static void WriteFile(FileInfo file, string text, bool writeToEndFlag = true)
To write text to the end of a file used:
bool writeToEndFlag = true
Example
string path = "AbsolutePathToFile";
FileInfo someFile = new FileInfo(path);
WorkerFiles.WriteFile(someFile, "SomeText");
or
WorkerFiles.WriteFile(someFile, "SomeText", false);
public static string ReadFile(FileInfo file, bool textflag=true)
bool textflag=true
Example
string path = "AbsolutePathToFile";
FileInfo someFile = new FileInfo(path);
Console.WriteLine(WorkerFiles.ReadFile(someFile));
or
Console.WriteLine(WorkerFiles.ReadFile(someFile, false));
public static string[] GetAllFilesInDir(string dirPath)
Example
string dirPath = "AbsolutePathToDirectory";
string[] allfiles = WorkerFiles.GetAllFilesInDir(dirPath);
public static string[] GetAllFilesInDirWithoutExtension(string dirPath)
Example
string dirPath = "AbsolutePathToDirectory";
string[] allfiles = WorkerFiles.GetAllFilesInDirWithoutExtension(dirPath);
public static string[] GetAllDirsInDir(string dirPath)
Example
string dirPath = "AbsolutePathToDirectory";
string[] allfiles = WorkerFiles.GetAllDirsInDir(dirPath);
public static string GetFileDir(string filePath)
Example
string path = "AbsolutePathToFile";
string parentFolder = GetFileDir(path);
public static string GetFileName(string filePath)
Example
string path = "AbsolutePathToFile";
string fileName = GetFileName(path);
public static void DeleteLineInFile(FileInfo file, int lineIndex)
Example
string path = "AbsolutePathToFile";
FileInfo someFile = new FileInfo(path);
int lineIndex = 4 // deletes 4th line
WorkerFiles.DeleteLineInFile(someFile, lineIndex);
- Use to work with JSON:
public static class AWorkerJson
public static void AddFileToJson(string path, string someFileName)
public static void AddAllDirsToJson(string dirPath, string someFileName)
public static void CreateJson(string someFileName)
public static void DeleteJson(string someFileName)
public static void ShowJsonFolder(bool flagWithoutExtension=false)
public static void ShowAllDirsInDir(string dirPath)
public static void DeleteFileFromJson(string someFileName, string stringToDelete)
public static void FindStringInFile(string someFileName, string stringToFind)
public static void ShowJsonFiles(string someFileName)
public static void FindStringInAllFiles(string stringToFind)
public static List<string> GetFilesFromJson(string someFileName)
public static string GetStringFromJsonLine(string file, string desiredString)
public static List<string> GetListFilesFromJson(List<string> list, string desiredString)