rory - 04 May 2006, 07:15 am
Use it for whatever you like, its free ..
Nothing to do with CCTV but it may come in handy.
Deletes All Files and SubFolders in a Specific Folder or SubFolder. Input box pops up and asks for the Full Path of the folder.
Some learning material if anything. Converted from ASP to standalone Vbscript. Copy text into a new text file and save as a .vbs file. If you want the ASP script let me know.
Nothing to do with CCTV but it may come in handy.
Deletes All Files and SubFolders in a Specific Folder or SubFolder. Input box pops up and asks for the Full Path of the folder.
Some learning material if anything. Converted from ASP to standalone Vbscript. Copy text into a new text file and save as a .vbs file. If you want the ASP script let me know.
CODE:
' This script was developed by Rory Knowles
' FREEWARE - Produced by BahamasSecurity.com
' Note, save this script as a .vbs file.
'----------------------------
Option Explicit
'----------------------------
'// PROGRAM SETTINGS
Const ProgTitle = "Delete Files & Folders"
'----------------------------
'// DECLARATIONS
Dim fso, f
Dim FileCnt
Dim FolderCnt
Dim folderName
FileCnt = 0
FolderCnt = 0
'----------------------------
'// GET FOLDER & PERFORM TASKS
Sub ParseFolder()
Set fso=CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderName)
Call DeleteFiles(f)
Call DeleteFolders(f)
Set f = Nothing
Set fso = nothing
Call EndMessage()
End Sub
'----------------------------
'// CHECK IF FOLDER EXISTS
Function DoesFolderExist()
Dim fso
Dim var
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(folderName)) Then
DoesFolderExist = True
end if
Set fso = nothing
End function
'----------------------------
'// DELETE FILES
Function DeleteFiles(byVal f)
Dim file
Dim Files
Set Files = f.Files
For Each file In Files
file.delete
FileCnt = FileCnt + 1
Next
Set Files = Nothing
End function
'----------------------------
'// DELETE FOLDERS
Function DeleteFolders(byVal f)
Dim SingleFolder
Dim SubFolders
Set SubFolders = f.Subfolders
For Each SingleFolder in SubFolders
SingleFolder.delete
FolderCnt = FolderCnt + 1
Next
Set SubFolders = nothing
End function
'----------------------------
'// FOLDER NOT EXIST
Sub badFolder()
msgBox("Folder: " & folderName &", does not exist! Operation Cancelled", vbOkOnly, ProgTitle)
End Sub
'----------------------------
'// END MESSAGE
Sub EndMessage()
Call MsgBox("Deleted " & FileCnt & _
" Files and " & FolderCnt & _
" SubFolders From: " & folderName, _
vbOkOnly, ProgTitle)
End Sub
'----------------------------
'// CANCEL BY USER
Sub operationCancelled()
Call MsgBox("User Cancelled", vbOkOnly, ProgTitle)
End Sub
'----------------------------
'// CHECK INPUT BOX ENTRY
Sub CheckFolderEntry()
folderName = InputBox("Enter Folder Path (eg: c:\test)", ProgTitle)
if folderName <>"" then
if DoesFolderExist() = True then
call ParseFolder()
else
call badFolder()
end if
else
call operationCancelled()
end if
End Sub
'----------------------------
'// START PROGRAM
Sub startRoutines()
Call CheckFolderEntry()
End Sub
'----------------------------
call startRoutines()
' This script was developed by Rory Knowles
' FREEWARE - Produced by BahamasSecurity.com
' Note, save this script as a .vbs file.
'----------------------------
Option Explicit
'----------------------------
'// PROGRAM SETTINGS
Const ProgTitle = "Delete Files & Folders"
'----------------------------
'// DECLARATIONS
Dim fso, f
Dim FileCnt
Dim FolderCnt
Dim folderName
FileCnt = 0
FolderCnt = 0
'----------------------------
'// GET FOLDER & PERFORM TASKS
Sub ParseFolder()
Set fso=CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderName)
Call DeleteFiles(f)
Call DeleteFolders(f)
Set f = Nothing
Set fso = nothing
Call EndMessage()
End Sub
'----------------------------
'// CHECK IF FOLDER EXISTS
Function DoesFolderExist()
Dim fso
Dim var
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(folderName)) Then
DoesFolderExist = True
end if
Set fso = nothing
End function
'----------------------------
'// DELETE FILES
Function DeleteFiles(byVal f)
Dim file
Dim Files
Set Files = f.Files
For Each file In Files
file.delete
FileCnt = FileCnt + 1
Next
Set Files = Nothing
End function
'----------------------------
'// DELETE FOLDERS
Function DeleteFolders(byVal f)
Dim SingleFolder
Dim SubFolders
Set SubFolders = f.Subfolders
For Each SingleFolder in SubFolders
SingleFolder.delete
FolderCnt = FolderCnt + 1
Next
Set SubFolders = nothing
End function
'----------------------------
'// FOLDER NOT EXIST
Sub badFolder()
msgBox("Folder: " & folderName &", does not exist! Operation Cancelled", vbOkOnly, ProgTitle)
End Sub
'----------------------------
'// END MESSAGE
Sub EndMessage()
Call MsgBox("Deleted " & FileCnt & _
" Files and " & FolderCnt & _
" SubFolders From: " & folderName, _
vbOkOnly, ProgTitle)
End Sub
'----------------------------
'// CANCEL BY USER
Sub operationCancelled()
Call MsgBox("User Cancelled", vbOkOnly, ProgTitle)
End Sub
'----------------------------
'// CHECK INPUT BOX ENTRY
Sub CheckFolderEntry()
folderName = InputBox("Enter Folder Path (eg: c:\test)", ProgTitle)
if folderName <>"" then
if DoesFolderExist() = True then
call ParseFolder()
else
call badFolder()
end if
else
call operationCancelled()
end if
End Sub
'----------------------------
'// START PROGRAM
Sub startRoutines()
Call CheckFolderEntry()
End Sub
'----------------------------
call startRoutines()
: