C#:生成常规文件的机制
使用计时器在 ASP.NET 站点中每隔 15 分钟就会生成以下常规文件 (date_time.zip)。
1027_0100.zip、1027_011*.zip、1027_0130.zip、...
我的问题是我需要一种机制来恢复在 3 天内以某种方式丢失的文件,例如 1026_0000.zip。您建议使用什么数据结构/算法来实现?
PS:我打算使用另一个计时器来定期恢复丢失的文件。
谢谢你!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于命名方案是已知的并且文件的去向是已知的。您只需生成每个潜在文件的名称,然后使用 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.
我将提出一个稍微不同的解决方案:而不是重复查询磁盘,只需使用 Directory.GetFiles(...) 和 Linq 来解决:
I'll propose a slightly different solution: rather than querying the disk repeatedly, just use Directory.GetFiles(...) and Linq against that: