udfDelFoldertree
int udfDelFoldertreeV1 (str)
int udfDelFoldertreeV2 (str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfDelFoldertreeV2 (strFolder)
intLastIC51 = IntControl (51, 16384, 0, 0, 0)
intResult = RunHideWait (Environment ("ComSpec"), '/C RD /S /Q "' : strFolder : '" >NUL: 2>&1')
IntControl (51, intLastIC51, 0, 0, 0)
Return intResult
;..........................................................................................................................................
; Parameter:
; strFolder ... The root folder of the foldertree to be deleted.
;
; Note:
; The deletion of all files and almost all directories is a hazardous act.
; Have caution on doing this! Folders and their files will be deleted without permission!
; There is no RecycleBin feature!
;..........................................................................................................................................
; IntControl (51, p1, 0, 0, 0) ; Specifies flags for CreateProcess.
; Value  Priority                     Description
;    32  NORMAL_PRIORITY_CLASS        Indicates a normal process with no special scheduling needs.
;    64  IDLE_PRIORITY_CLASS          Indicates a process whose threads run only when the system is idle and are preempted by the threads of any process running in a higher priority class. An example is a screen saver. The idle priority class is inherited by child processes.
;   128  HIGH_PRIORITY_CLASS          Indicates a process that performs time-critical tasks that must be executed immediately for it to run correctly. The threads of a high-priority class process preempt the threads of normal or idle priority class processes. An example is the Task List, which must respond quickly when called by the user, regardless of the load on the operating system. Use extreme care when using the high-priority class, because a high-priority class CPU-bound application can use nearly all available cycles.
;   256  REALTIME_PRIORITY_CLASS      Indicates a process that has the highest possible priority. The threads of a real-time priority class process preempt the threads of all other processes, including operating system processes performing important tasks. For example, a real-time process that executes for more than a very brief interval can cause disk caches not to flush or cause the mouse to be unresponsive.
; 16384  BELOW_NORMAL_PRIORITY_CLASS  Windows NT and Windows Me/98/95: This value is not supported. Indicates a process that has priority above IDLE_PRIORITY_CLASS but below NORMAL_PRIORITY_CLASS.
; 32768  ABOVE_NORMAL_PRIORITY_CLASS  Windows NT and Windows Me/98/95: This value is not supported. Indicates a process that has priority above NORMAL_PRIORITY_CLASS but below HIGH_PRIORITY_CLASS.
;..........................................................................................................................................
; Detlev Dalitz.20101006.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfDelFoldertreeV1 (strFolder)
strFolderHome = DirGet ()
ErrorMode (@OFF)
DirChange (strFolder)
ErrorMode (@CANCEL)
If LastError () > 0 Then Return 0
intLastIC5 = IntControl (5, 1, 0, 0, 0) ; System & Hidden files or directories are seen and used.
strFolderList = DirItemize ("*.*")
DirAttrSet (strFolderList, "rash")
intItems = ItemCount (strFolderList, @TAB)
For intItem = 1 To intItems
   strFolderThis = ItemExtract (intItem, strFolderList, @TAB)
   intResult = udfDelFoldertreeV1 (strFolderThis) ; Recursive.
Next
FileAttrSet ("*.*", "rash")
intResult = FileDelete ("*.*")
intResult = DirChange ("..")
If DirExist (strFolder) Then intResult = DirRemove (strFolder)
intResult = DirChange (strFolderHome)
IntControl (5, intLastIC5, 0, 0, 0) ; Restore previous setting, e. g. protect System & Hidden files and directories.
Return 1
;..........................................................................................................................................
; Parameter:
; strFolder ... The root folder of the foldertree to be deleted.
;
; Note:
; This udf can see hidden & system directory attribute by IntControl(5,1,0,0,0).
; The deletion of all files and almost all directories is a hazardous act.
; Have caution on doing this! Folders and their files will be deleted without permission!
; There is no RecycleBin feature!
;
; Based on Article in WinBatch TechBase.
; Article ID:   W14748
; Filename:   DelTree and Xcopy.txt
; File Created: 2001:03:19:15:12:22
;
; Modified by Detlev Dalitz.20020530.20080725.20101006.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test Version 1.
; intResult = udfDelFoldertreeV1 (strFolder)

DirChange (DirScript ())
strMsgTitle = "Test udfDelFoldertreeV1()"

; Change to the user temp folder.
strFolderTemp = ShortCutDir ("Local Settings") : "\Temp\"
DirChange (strFolderTemp)

; Create a test foldertree in the user temp folder.
; For simple testcase we create no files, but set some directory attributes.
DirMake ("FoldertreeRoot\FolderA1\FolderB1\FolderC1")
DirMake ("FoldertreeRoot\FolderA1\FolderB1\FolderC2")
DirMake ("FoldertreeRoot\FolderA1\FolderB1\FolderC3")
DirMake ("FoldertreeRoot\FolderA1\FolderB1\FolderC4")
DirMake ("FoldertreeRoot\FolderA1\FolderB2\")
DirMake ("FoldertreeRoot\FolderA1\FolderB3\")
DirMake ("FoldertreeRoot\FolderA2\")
DirAttrSet("FoldertreeRoot\FolderA1\FolderB1\FolderC4", "RASH")
DirAttrSet("FoldertreeRoot\FolderA1\FolderB3\", "RASH")
DirAttrSet("FoldertreeRoot\FolderA2\", "RASH")

If DirExist ("FoldertreeRoot")
   strMsgText = "The test foldertree exists."
   Pause (strMsgTitle, strMsgText)

   intResult = udfDelFoldertreeV1 ("FoldertreeRoot")

   If DirExist ("FoldertreeRoot")
      strMsgText = "The foldertree still exists."
   Else
      strMsgText = "The foldertree has been removed."
   EndIf
   Pause (strMsgTitle, strMsgText)
Else
   strMsgText = "Ooops, there is no foldertree."
   Pause (strMsgTitle, strMsgText)
EndIf


; Test Version 2.
; intResult = udfDelFoldertreeV2 (strFolder)

DirChange (DirScript ())
strMsgTitle = "Test udfDelFoldertreeV2()"

; Change to the user temp folder.
strFolderTemp = ShortCutDir ("Local Settings") : "\Temp\"
DirChange (strFolderTemp)

; Create a test foldertree in the user temp folder.
; For simple testcase we create no files, but set some directory attributes.
DirMake ("FoldertreeRoot\FolderA1\FolderB1\FolderC1")
DirMake ("FoldertreeRoot\FolderA1\FolderB1\FolderC2")
DirMake ("FoldertreeRoot\FolderA1\FolderB1\FolderC3")
DirMake ("FoldertreeRoot\FolderA1\FolderB1\FolderC4")
DirMake ("FoldertreeRoot\FolderA1\FolderB2\")
DirMake ("FoldertreeRoot\FolderA1\FolderB3\")
DirMake ("FoldertreeRoot\FolderA2\")
DirAttrSet("FoldertreeRoot\FolderA1\FolderB1\FolderC4", "RASH")
DirAttrSet("FoldertreeRoot\FolderA1\FolderB3\", "RASH")
DirAttrSet("FoldertreeRoot\FolderA2\", "RASH")

If DirExist ("FoldertreeRoot")
   strMsgText = "The test foldertree exists."
   Pause (strMsgTitle, strMsgText)

   intResult = udfDelFoldertreeV2 ("FoldertreeRoot")

   If DirExist ("FoldertreeRoot")
      strMsgText = "The foldertree still exists."
   Else
      strMsgText = "The foldertree has been removed."
   EndIf
   Pause (strMsgTitle, strMsgText)
Else
   strMsgText = "Ooops, there is no foldertree."
   Pause (strMsgTitle, strMsgText)
EndIf

:CANCEL
Exit