Delete Subfolder and Files
- Details
- Category: VBS
- Created: Sunday, 01 January 2012 09:58
- Last Updated: Friday, 10 November 2017 18:48
- Published: Sunday, 01 January 2012 09:58
- Written by Frank
- Hits: 9288
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: " & 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: " & 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