查找旧文件并将其删除 [英] Find old files and delete them

查看:64
本文介绍了查找旧文件并将其删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个数据库,前端只有代码,四个后端只有数据。我有几个后端来管理数据库的大小,以及在一个地方分组数据,这使得它更容易管理(个人喜好)。


每当我的FE打开,它会检查上次备份BE的时间,如果超过六个小时,它将复制BE并将它们保存到备份文件夹中。数据库还为每个副本添加了一个时间戳,因此我知道,仅通过查看文件名,何时备份文件。文件本身可能超过30天,因为并非每天都会访问我的所有BE。在数据库被打开的情况下备份它肯定会导致事情快速失控。


然而,正如你猜测的那样,每天多次备份几个BE(范围每个4-50 MB)很快就会对存储空间造成压力。现在,我偶尔会进入我的BACKUP文件夹,查找旧文件(> 30天)并删除它们。


这是我想要做的:


当FE打开时,让数据库检查文件列表,找到日期戳,解码它,如果文件已在超过30天前备份,则将其删除。这样,我只有不超过30天的BE值。


我的挑战是,如何告诉数据库转到特定目录并通过文件列表?那么,VBA是否可以从目录中删除文件?


任何帮助都将受到赞赏。


作为参考,这里是我用于备份的代码:

展开 | 选择 | Wrap | 行号

解决方案

一切皆有可能。


使用 Dir()识别文件夹中的所有匹配文件。当你拥有它时(在循环中)解析每个文件名。如果文件名反映的是30天前的日期,则使用 Kill 语句将其删除。


问题范围太宽,只是为了提供解决方案但是如果你努力从这些指针中提供一个,那么如果你在路上的任何地方挣扎,我们可以帮助解决具体细节。


PS。这可以通过文件系统对象库(FSO)来完成,但也可以使用VBA和提供的内置函数完成它。


如果它可能对你有所帮助空间问题,您可以使用方法DBEngine.CompactDatabase作为备份例程的一部分。


在代码Mario中这样做有点意义。 Access具有内置选项,可以在关闭时自动压缩和修复。查看网页上有关此方法的可行性的各种评论,但如果您选择使用它,则可以在 T ools \ 中找到该设置。 0 ptions

I currently have a database with a front end of just code and four back-ends with just data. I have several back ends to manage the size of the databases, as well as to group like data in one place, which makes it easier to manage (personal preference).

Whenever my FE opens, it checks to see the last time the BEs were backed up and if it has been more than six hours, it will make copies of the BEs and save them to a Backup folder. The DB also adds a time stamp to each copy, so that I know, just by looking at the file name, when the file was backed up. The file itself, may be older than 30 days, because not all of my BEs are accessed every day. Having it back up EVERY time the DB was opened would definitely cause things to quickly get out of hand.

However, as you can guess, backing up several BEs several times a day (ranging from 4-50 MB each) quickly causes a strain on storage space. Right now, I occasionally go into my BACKUP folder, find the older files (>30 days) and just delete them.

Here is what I want to do:

When the FE opens, have the DB check the list of files, find the date stamp, decode it, and if the file was backed up more than 30 days ago, delete it. This way, I will only have no more than 30 days'' worth of BEs.

My challenge is, how do I tell the DB to go to a particular directory and go through a list of files? Then, is it possible for VBA to delete files from a directory?

Any assistance would be appreciated.

For reference, here is the code I use for my backup:

Expand|Select|Wrap|Line Numbers

解决方案

It''s all possible.

Use Dir() to identify all the matching files in the folder. Parse the filename for each when you have it (in your loop). If the filename reflects a date earlier than 30 days ago then delete it using the Kill statement.

The question is too broad of scope simply to provide a solution, but if you work on providing one from these pointers then we can probably help with particular details if you struggle anywhere along the way.

PS. This can be done with the File System Objects library (FSO), but it can also be done quite simply using just VBA and the inbuilt functions provided.


If it might help a bit on your space issue, you could use the method DBEngine.CompactDatabase as part of your backup routine.


There''s little point in doing that in code Mario. Access has an inbuilt option for databases to Compact and Repair automatically on close. Check out the web for various comments as to the advisability of this approach, but if you choose to use it then the setting can be found in Tools \ Options.


这篇关于查找旧文件并将其删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆