[英]How to compress last modified file in C#
我在目錄中有很多同名文件。 我想在MyDirectory中壓縮(壓縮等)最后修改的文件。 你能幫我嗎?
我可以壓縮文件,但不能壓縮最后修改的文件:
private void button1_Click(object sender, EventArgs e)
{
FileStream sourceFile = File.OpenRead(@"C:\MyDirectory");
FileStream destFile = File.Create(@"C:\MyDirectory.zip");
GZipStream compStream = new GZipStream(destFile, CompressionMode.Compress);
try
{
int theByte = sourceFile.ReadByte();
while (theByte != -1)
{
compStream.WriteByte((byte)theByte);
theByte = sourceFile.ReadByte();
}
}
finally
{
compStream.Dispose();
}
MessageBox.Show("file is compressed successfully");
}
要獲取最后修改的文件:
string lastModified = Directory.EnumerateFiles(path)
.OrderBy(f => File.GetLastWriteTime(f))
.Last();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.