Ignore Empty files C#

Viewed 56

I am trying to avoid empty files in my Program and the way i am doing it doesnt work.

I got a machschine that create logs, at Weekend is nobody here and but the maschine create a file with only 5,6 lines, the right one should have 20k lines.

I know there is FileInfo.Length but i dont know how to use it with this what a have right now.

public List<SystemLogFileData> ProcessSystemLogFiles(List<string> systemLogsFilePaths)
{
    List<SystemLogFileData> systemLogFilesData = new List<SystemLogFileData>();

    foreach (var filePath in systemLogsFilePaths)
    {
        string[] lines = System.IO.File.ReadAllLines(filePath);
        var systemLogFileData = ProcessSystemLogFile(lines.ToList());

        if (File.ReadAllText(systemLogFileData).Length > 100)
        {
            systemLogFilesData.Add(systemLogFileData);
        }
    }

    return systemLogFilesData;
}
1 Answers

I solved it and it works well. Not in my main Program but in Autobackup.

insted of ignoring the the not important file i don't copy them and i reached my goal.

Thakns for the help!

    //path of file
    string pathToOriginalFile = @"C:\Users\Desktop\c#\Logging\Systemlog.bk66";


    //duplicate file path 
    string PathForDuplicateFile = @"C:\\\Desktop\c#\Systemlog";

    //rename fileName if Exists
    FixFileName(ref PathForDuplicateFile, ".bk");

    if (File.ReadAllText(pathToOriginalFile).Length > 2000)
    {

        File.Copy(pathToOriginalFile, PathForDuplicateFile);

    }
      else
    {
      

    }
    //provide source and destination file paths
Related