2012-05-04 43 views
1

我需要開發donwload所有文件大小等於0,從驅動器C.我已經做了的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盤的根目錄下刪除文件!我需要在此代碼中使用recusrive,但我是VBScript中的新成員,並且不知道如何執行此操作。請,我希望你能幫助我。謝謝。

+1

什麼是這樣的:http://www.wisesoft.co.uk/scripts/vbscript_recursive_file_delete_by_extension.aspx – HK1

回答

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 
相關問題