Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe '##
#Dim All
#Include "Win32api.inc"
'______________________________________________________________________________
Function RecursiveFileFolderDelete(StartIn As String) As Long
Local WinFindData As WIN32_FIND_DATA
Local hFileFind As Dword
If Asc(StartIn , - 1) <> 92 Then StartIn = StartIn & "\" 'Add backslash if none
hFileFind = FindFirstFile(StartIn & "*", WinFindData)
If hFileFind <> %INVALID_HANDLE_VALUE Then
Do
If (WinFindData.dwFileAttributes And %FILE_ATTRIBUTE_DIRECTORY) Then 'It's a folder
If WinFindData.cFilename <> "." And WinFindData.cFilename <> ".." Then
RecursiveFileFolderDelete(StartIn & WinFindData.cFilename)
RemoveDirectory(StartIn & WinFindData.cFilename)
End If
Else 'Its a file
'SetFileAttributes(StartIn & WinFindData.cFilename, %FILE_ATTRIBUTE_NORMAL) 'Optional
DeleteFile(StartIn & WinFindData.cFilename) 'ERROR_ACCESS_DENIED if read-only file
End If
Loop While FindNextFile(hFileFind, WinFindData)
FindClose(hFileFind)
End If
End Function
'______________________________________________________________________________
Function PBMain() As Long
RecursiveFileFolderDelete("c:\users\gbeen\desktop\testB")
Beep
? "Done"
End Function
http://www.garybeene.com/sw/gbsnippets.htm