如何从 Objective-C 的文档目录中删除旧文件?
我想从 Objective-C 中用户的 ~documents
目录中删除旧文件(15 天或更早)。有没有办法知道文件何时创建并随后删除它们?
I would like to delete old files (15 days or older) from the user's ~documents
directory in objective-c. Is there a way to know when a file was created and subsequently delete them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不完全理解你的问题,但我假设你想要一种让 Mac 应用程序识别旧文件并删除它们的方法。如果是这样,请尝试以下操作:
这将为目录中的每个日期获取一个日期(只需将字符串
@"/samplePath"
替换为实际路径)。然后,您可以进行日期数学运算以找出它被修改的时间。或者,您可以将NSFileModificationDate
替换为NSFileCreationDate
以获取文件的创建时间。I don't completely understand your question, but I'm going to assume you want a way for a Mac application to identify old files and delete them. If so, try this:
That will get a date for each date in a directory (just substitute the string
@"/samplePath"
with an actual path). Then, you can do the date math to find how long ago it was modified. Alternatively, you could replaceNSFileModificationDate
withNSFileCreationDate
to get when the files were created.