如何制作脚本以递归下载所有空文件?

时间:2012-05-04 14:16:50

标签: vbscript

我需要开发VBScript,从驱动器C下载大小等于0的所有文件。我已经制作了以下脚本:

Dim oFSO 
Dim sDirectoryPath
Dim oFolder  
Dim oFileCollection
Dim oFile
Dim oFolderCollection
Dim n
Set oFSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = "C:\"
set oFolder = oFSO.GetFolder(sDirectoryPath)
set oFolderCollection = oFolder.SubFolders
set oFileCollection = oFolder.Files
For each oFile in oFileCollection
    IF oFile.Size = 0 Then
        oFile.Delete(true)
    END IF
Next    

但是这个脚本只删除驱动器C根目录下的文件!我需要在这段代码中使用recusrive,但我是VBScript的新手,不知道我该怎么做。拜托,我希望你能帮助我。谢谢。

1 个答案:

答案 0 :(得分:0)

这是经过测试和运作的脚本

set oFso = createobject("scripting.filesystemobject")
sDirectorypath = "c:\testing"
delete_empty_files(sDirectorypath)

sub delete_empty_files(folder)
  set oFolder = oFso.getfolder(folder)
  for each oFile in oFolder.files
    if oFile.size = 0 then
      wscript.echo " deleting " & oFile.path
      oFile.delete(true)
    end if
  next
  for each oSubFolder in oFolder.subfolders
    delete_empty_files(oSubFolder)
  next
end sub