Vbscript 如何使用VBS脚本删除目录树中早于10天的所有文件?

Vbscript 如何使用VBS脚本删除目录树中早于10天的所有文件?,vbscript,Vbscript,我有一个服务器,里面有很多文件夹C:\data。我讨论了大约5000个子文件夹,每个文件夹都有一个随机名称,比如sgshVSHsXx.wjwuhhs 每个文件夹都包含名为DB的子文件夹,每个DB文件夹都包含一些数据库文件,还包含随机文件名和随机文件扩展名 我需要检查所有那些DB文件夹,删除所有超过10天的文件 我想我可以使用一些VBS来实现这一点,但我没有太多的经验。有人能解释一下这个问题吗 谢谢将以下内容另存为.vbs文件 set args = wscript.arguments if arg

我有一个服务器,里面有很多文件夹
C:\data
。我讨论了大约5000个子文件夹,每个文件夹都有一个随机名称,比如
sgshVSHsXx.wjwuhhs

每个文件夹都包含名为
DB
的子文件夹,每个
DB
文件夹都包含一些数据库文件,还包含随机文件名和随机文件扩展名

我需要检查所有那些
DB
文件夹,删除所有超过10天的文件

我想我可以使用一些VBS来实现这一点,但我没有太多的经验。有人能解释一下这个问题吗


谢谢

将以下内容另存为.vbs文件

set args = wscript.arguments
if args.count <> 2 then
    wscript.echo "Syntax: " & wscript.scriptname & " <path> <days>" 
    wscript.quit
end if

path = args(0)
killdate = date() - args(1)

arFiles = Array() 
set fso = createobject("scripting.filesystemobject") 

SelectFiles path, killdate, arFiles, true 

nDeleted = 0 
for n = 0 to ubound(arFiles) 

  on error resume next 'in case of 'in use' files... 
  arFiles(n).delete true 
  if err.number = 0 then 
     nDeleted = nDeleted + 1 
  end if 
  on error goto 0 
next 

sub SelectFiles(sPath,vKillDate,arFilesToKill,bIncludeSubFolders) 
  on error resume next 
  set folder = fso.getfolder(sPath) 
  set files = folder.files 

  for each file in files 
    dtlastmodified = null 
    on error resume Next 
    dtlastmodified = file.datelastmodified 
    on error goto 0 
    if not isnull(dtlastmodified) Then 
      if dtlastmodified < vKillDate then 
        count = ubound(arFilesToKill) + 1 
        redim preserve arFilesToKill(count) 
        set arFilesToKill(count) = file 
      end if 
    end if 
  next 

  if bIncludeSubFolders then 
    for each fldr in folder.subfolders 
      SelectFiles fldr.path,vKillDate,arFilesToKill,true 
    next 
  end if 
end sub
set args=wscript.arguments
如果args.count为2,则
wscript.echo“语法:&wscript.scriptname&”
wscript.quit
如果结束
路径=args(0)
killdate=date()-args(1)
arFiles=Array()
设置fso=createobject(“scripting.filesystemobject”)
选择文件路径、killdate、arFiles、true
n删除=0
对于n=0到ubound(arFiles)
出现错误时,在“正在使用”文件的情况下继续下一步。。。
arFiles(n).删除true
如果err.number=0,则
n删除=n删除+1
如果结束
错误转到0
下一个
子选择文件(sPath、vKillDate、arFilesToKill、bIncludeSubFolders)
出错时继续下一步
set folder=fso.getfolder(sPath)
set files=folder.files
对于文件中的每个文件
dtlastmodified=null
出错时继续下一步
dtlastmodified=file.datelastmodified
错误转到0
如果不为空(dtlastmodified),则
如果dtlastmodified
要运行: .vbs“

例如: c:\delete.vbs“c:\test folder\”10

确保从管理命令提示符下运行

#
来源:

当然,批处理或命令提示符适用于此

forfiles /p "c:\data" /m * /s /d -10 /c "cmd /c del @path"

只有一行。

您对哪一部分特别有问题?