1

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

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 的根目录中删除文件!我需要在这段代码中使用 recusive,但我是 VBScript 的新手,不知道该怎么做。拜托,我希望你能帮助我。谢谢你。

4

1 回答 1

0

here a tested and working script

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
于 2012-05-05T20:19:49.910 回答