C#:生成常规文件的机制

发布于 2024-12-12 01:52:29 字数 252 浏览 1 评论 0 原文

使用计时器在 ASP.NET 站点中每隔 15 分钟就会生成以下常规文件 (date_time.zip)。

1027_0100.zip、1027_011*.zip、1027_0130.zip、...

我的问题是我需要一种机制来恢复在 3 天内以某种方式丢失的文件,例如 1026_0000.zip。您建议使用什么数据结构/算法来实现?

PS:我打算使用另一个计时器来定期恢复丢失的文件。

谢谢你!

following regular files (date_time.zip) would be generated at 15-min interval in ASP.NET site with Timer.

1027_0100.zip, 1027_011*.zip, 1027_0130.zip, ...

My question is I need a mechanism to restore files which are somehow missed within 3 days, like 1026_0000.zip. What data structure/algorithm would you recommend to use to implement?

PS: I intend to use another Timer to regularly restore missing files.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迟到的我 2024-12-19 01:52:29

由于命名方案是已知的并且文件的去向是已知的。您只需生成每个潜在文件的名称,然后使用 System.Io.file.Exists。如果该调用失败,则重新生成文件。

Since the naming scheme is know and the where the files are going is know. You simply need to generate what would be the name for each potential file and then check its existence using the System.Io.file.Exists. If that call fails regenerate the file.

苍景流年 2024-12-19 01:52:29

我将提出一个稍微不同的解决方案:而不是重复查询磁盘,只需使用 Directory.GetFiles(...) 和 Linq 来解决:

string[] files_that_should_exist = YourMethodToGenerateExistingFilenames();
string[] files_in_dir = System.IO.Directory.GetFiles(output_path);

var missing_files = files_that_should_exist.Except(files_in_dir);

foreach(string file in missing_files) YourMissingFileGenerateMethod(file);

I'll propose a slightly different solution: rather than querying the disk repeatedly, just use Directory.GetFiles(...) and Linq against that:

string[] files_that_should_exist = YourMethodToGenerateExistingFilenames();
string[] files_in_dir = System.IO.Directory.GetFiles(output_path);

var missing_files = files_that_should_exist.Except(files_in_dir);

foreach(string file in missing_files) YourMissingFileGenerateMethod(file);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文