Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe "fastfolderkiller.exe"
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Global NewFolder$
Global qFreq, qStart, qStop As Quad
Function PBMain() As Long
Local Folder$ = "c:\users\gbeen\desktop\test50\"
QueryPerformanceFrequency qFreq
QueryPerformanceCounter qStart
FastFolderKiller(Folder$)
QueryPerformanceCounter qStop
? Format$((qStop-qStart)/qFreq,"###.0") & "s"
Beep
End Function
Sub FastFolderKiller(Folder$)
Folder$ = Trim$(Folder$) 'remove spaces on either end
If Dir$(Folder$ + "*.*", %SubDir) <> "" Then Exit Sub 'has subfolders, which this function cannot handle
If Right$(Folder$,1) <> "\" Then Folder$ += "\" 'must have a trailing \
If IsFalse IsFolder(Folder$) Then Exit Sub 'not a folder
If Dir$(Folder$ + "*.*") = "" Then RmDir Exit Sub 'no files, so remove with RmDir. No further action required.
NewFolder$ = NewFolderName 'call function that gets a unique new folder name
Name Folder$ As NewFolder$ 'make way to create an empty Folder$
MkDir Folder$ 'crete an empty Folder$, as though it's files had been deleted
Thread Create SilentKiller(0) To hThread 'get rid of the renamed folder in the background
Thread Close hThread To hThread : hThread = 0 'make hThread handle available
Function = 1 '1 = success 0 = fail
End Sub
Function NewFolderName$(Folder$) As String
'is there an API to get a guaranteed unique folder name?
'get next available folder name "folder_being_killed_0000" through "folder_being_killed_9999"
Local tempFolder$
For i = 0 To 9999
tempFolder$ = "folder_being_killed_" + Format$(i,"0000")
If IsFalse IsFolder(tempFolder$) Then Function = tempFolder$ : Exit Function
Next i
End Sub
Thread Function SilentKiller(ByVal x As Long) As Long
Kill NewFolder$ + "*.*" '? how to pass NewFolder$ other than Global variable
RmDir NewFolder$
End Function
http://www.garybeene.com/sw/gbsnippets.htm