Tuesday, April 28, 2009

KiXtart Script: Delete Files in Selected Folder

This is another VBScript-to-KiXtart conversion diversion transfusion illusion, which prompts for a folder, and then deletes all the files in the folder.  This one just clears out the selected folder.  It won't delete subfolders or recurse into subfolders to delete their files.  I could add that but I saw the weather was too nice out and got distracted.  Basically, I'm just too lazy.



;----------------------------------------------------------------
; Filename..: CleanOut_Folder.kix
; Author....: David M. Stein
; Date......: mm/dd/yyyy
; Purpose...: select folder to clean out files within
;----------------------------------------------------------------
Break ON

$FileSpec = "*.*"

$objShell = CreateObject("Shell.Application")
$objFolder = $objShell.BrowseForFolder (0, "Select The Folder To
Enumerate :", (0))

If $objFolder = 0
Exit
Else
$objFolderItem = $objFolder.Self
$objPath = $objFolderItem.Path
EndIf

? "Path: $objPath"

$FileCount = 0
$FileName = Dir("$objPath\$FileSpec")
While $FileName <> "" And @ERROR = 0
If $FileName <> "." And $FileName <> ".."
? "Deleting: $objPath\$FileName"
Del "$objPath\$FileName" /f /h /c
$FileCount = $FileCount + 1
EndIf
$FileName = Dir()
Loop

? "Deleted $FileCount files"
Post a Comment