到目前为止,我有一个代码每 2 秒截取一次屏幕截图并将它们保存到一个文件夹中。我想为程序添加一个功能,每 2 小时截取一次这些屏幕截图并将其压缩。我目前正在努力弄清楚如何在我的代码中设置单个计时器,但之后我需要添加它。
我一直在查找并尝试学习如何去做,但我对 c# 代码的了解非常有限。
我尝试将以下内容添加到我的代码中
using System.IO.Compression
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, true);
string extractPath = @"c:\example\extract";
ZipFile.ExtractToDirectory(zipPath, extractPath);
但它返回“不需要使用指令”。用于 System.IO.Compression。另外,我无法弄清楚我的 C:\Intel\Logs\dsp 目录如何适合每个字段,即。
c:\example\start
c:\example\result.zip
c:\example\extract
有人可以帮我弄清楚我做错了什么并向我解释(以非常明目张胆的方式)我该如何解决?非常感谢!
PS 在这部分添加会创建 zip 文件并将其隐藏吗?另外,我应该为那条线放哪条路?
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, true);
File.SetAttributes("c:\example\whichpath", FileAttributes.Hidden); //HERE
string extractPath = @"c:\example\extract";
ZipFile.ExtractToDirectory(zipPath, extractPath);
从这里您需要添加评论建议如下:
using System.IO.Compression;
using System.IO.Compression.FileSystem;
...
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
ZipFile.CreateFromDirectory(startPath, zipPath);
// and hide it
File.SetAttributes(zipPath, File.GetAttributes(zipPath) | FileAttributes.Hidden);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句