32 lines
815 B
C#
32 lines
815 B
C#
|
using System.Text;
|
|||
|
|
|||
|
string[] files = Directory.GetFiles("/var/data");
|
|||
|
|
|||
|
long maxFileLength = 0;
|
|||
|
|
|||
|
string maxFileLengthPath = "";
|
|||
|
|
|||
|
foreach (string file in files)
|
|||
|
{
|
|||
|
var fileInfo = new FileInfo(file);
|
|||
|
|
|||
|
if(fileInfo.Length > maxFileLength)
|
|||
|
{
|
|||
|
maxFileLength = fileInfo.Length;
|
|||
|
|
|||
|
maxFileLengthPath = file;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
using (FileStream fstream = File.OpenRead(maxFileLengthPath))
|
|||
|
{
|
|||
|
byte[] buffer = new byte[fstream.Length];
|
|||
|
await fstream.ReadAsync(buffer, 0, buffer.Length);
|
|||
|
string text = Encoding.Default.GetString(buffer);
|
|||
|
using (FileStream fstream1 = new FileStream("/var/result/data.txt", FileMode.OpenOrCreate))
|
|||
|
{
|
|||
|
fstream1.SetLength(0);
|
|||
|
byte[] buffer1 = Encoding.Default.GetBytes(text);
|
|||
|
await fstream1.WriteAsync(buffer1, 0, buffer1.Length);
|
|||
|
}
|
|||
|
}
|