如果在使用vbscript进行新备份后文件夹中有超过15个文件,如何删除备份文件夹中最旧的文件?

时间:2018-02-05 14:28:45

标签: vbscript

如果使用vbscript进行新备份后文件夹中的文件超过15个,如何删除备份文件夹中最旧的文件?

我发现我的备份在我的硬盘上占用了足够的空间

是否可以通过计算文件夹中的文件数来实现?我的备份名为“ST-06.02.18 07h20.zip”。我可以随时更改名称,如果它更容易... xd

Dim objFSO, objFolder, strDirectory, dNow, yy, mt, dd, hh, nn, objShell, dOpen
Set objFSO = CreateObject("Scripting.FileSystemObject")
strDirectory = "c:\test\"

If objFSO.FolderExists(strDirectory) Then
   Set objFolder = objFSO.GetFolder(strDirectory)
   WScript.Echo strDirectory & " already created "
Else
   Set objFolder = objFSO.CreateFolder(strDirectory)
   WScript.Echo "Just created " & strDirectory
End If



dNow = Now
yy = Right(Year(dNow), 2)
mt = Right("00" &Month(dNow), 2)
dd = Right("00" &Day(dNow), 2)
hh = Right("00" &Hour(dNow), 2)
nn = Right("00" &Minute(dNow), 2)
ss = Right("00" &Second(dNow), 2)



Compress "C:\Program Files\ST\Db" ,strDirectory & "ST-" &dd & "." &mt & "." &yy & " " &hh & "h" &nn &".zip"

Sub Compress(Input, ZipFile)
Dim Shell : Set Shell = CreateObject("Shell.Application")
Dim FSO : set FSO = CreateObject("Scripting.fileSystemObject")
FSO.CreateTextFile(ZipFile, true).WriteLine "PK" & Chr(5) & Chr(6) & String(18, 0)
Set ZipFile = Shell.NameSpace(ZipFile) 
ZipFile.CopyHere Input
Do Until ZipFile.items.Count = 1 
'important, makes the script not fall out and dispose of objects before they are done
'items.count is the amount of root items you anticipate to be in the zip file
        wscript.sleep 200
Loop
Set Shell = Nothing
Set FSO = Nothing
Set ZipFile = Nothing
End Sub

Set objShell = CreateObject("Wscript.Shell")
dOpen = "explorer.exe /e," & strDirectory
objShell.Run  dOpen

1 个答案:

答案 0 :(得分:1)

@forelse ($transactions ? $transactions : [] as $transaction)
    <tr>
        <td class="text-center">{{ $transaction->TranId }}</td>
        <td class="text-center">{{ $transaction->TranDate }}</td>
        <td class="text-center">{{ $transaction->SubType }}</td>
        <td class="text-center">{{ $transaction->FiledDate }}</td>
        <td class="text-center">{{ number_format($transaction->Amount, 2, '.', ',') }}</td>
    </tr> @empty
    <tr><td colspan="5">No Transactions</td></tr> @endforelse

此示例代码在文件夹大于2 gig时运行,并删除最旧的文件,直到2 gig以下。

它使用在内存中创建的断开连接的记录集来按最后修改的方式对文件进行排序。