|
发表于 2008-5-6 15:19:36
|
显示全部楼层
我觉得使用VBScript会方便些,思路供你参考:
我没有算备份目录中有多少个文件夹,我是检查每个文件夹的日期,如果日期超过30天,就将它删掉。
将下面的保存取一个名为Housekeep.vbs的文件,然后运行:
CScript //nologo Housekeep.vbs %BACKUP_SVN_ROOT% 30- Dim strPath ' 备份的目录
- Dim dayKept ' 需要保留的时间,以天为单位
- strPath=WScript.Arguments.Item(0)
- dayKept=WScript.Arguments.Item(1)
- Dim fileSystemObject, folderInfo, folderCollection, subFolder
-
- Set fileSystemObject = CreateObject("Scripting.FileSystemObject")
- Set folderInfo = fileSystemObject.GetFolder(strPath)
- Set folderCollection = folderInfo.SubFolders
- '列出备份目录的子文件夹
- For Each subFolder in folderCollection
- ' 检查文件夹的修改时间,如果超过需要保留的时间,删除整个文件夹
- If (DateDiff("d", subFolder.DateLastModified, Now) > CInt(dayKept) ) Then
- fileSystemObject.DeleteFolder(subFolder)
- End If
- Next
复制代码 |
|