Delete Subfolder and Files

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

Ordner und Dateien im angegebenen Pfad löschen.

Aufruf: cscript DeleteSubfolderandFiles.vbs C:\Windows\SoftwareDistribution\Download
Remote: cscript DeleteSubfolderandFiles.vbs \\SERVER1\C$\Windows\SoftwareDistribution\Download

Visual Basic Code:
'<!--******************************************************************** '* '* File: DeleteSubfolderandFiles.vbs '* Author: Frank '* Created: 19.02.2010 '* Version: 1.00 '* Modified: 00.00.0000 '* '* Description: Löscht Ordner und Dateien im angegebenen Pfad. '* '* needed: '* '* '* '********************************************************************--> Option Explicit Dim strComputer, strPath strPath = WScript.Arguments.Item(0)   'strPath = "C:\Windows\SoftwareDistribution\Download" DelDownload strPath   Function DelDownload(strPath) On Error Resume Next Dim FSO, Folder, File, SysRoot Set FSO = CreateObject("Scripting.FileSystemObject") Set Folder = FSO.GetFolder(strPath) For Each File In Folder.Files WScript.Echo "try to delete: " &amp; File.Name FSO.DeleteFile File, True If Err.Number = 0 Then Wscript.Echo "Deleting file succeeded." DelDownload = True Else Wscript.Echo "Deleting file succeeds with error." Wscript.Echo, Err.Description Err.Clear DelDownload = False End If Next If Folder.SubFolders.count > 0 Then For Each Folder In Folder.SubFolders WScript.Echo "try to delete: " &amp; Folder.Name FSO.DeleteFolder Folder, True If Err.Number = 0 then Wscript.Echo "Deleting folder succeeded." DelDownload = True Else Wscript.Echo "Deleting folder succeeded with error." Wscript.Echo Err.Description Err.Clear DelDownload = False End If Next End If set Folder = Nothing set FSO = Nothing End Function