Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Button
End Enum
Global hDlg As Dword, FileCount, FolderCount As Long
Function PBMain() As Long
Dialog New Pixels, 0, "Format Flash Drive",,,300,50, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Wipe Drive", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
WipeDrive("F:")
? "FolderCount: " + Str$(FolderCount) + $CrLf + "FileCount: " + Str$(FileCount)
End Select
End Select
End Function
Sub WipeDrive(ByVal Drive As String)
Local iPos As Long, tempINFO As DirData, temp$
If LCase$(Drive) = "c:" Or LCase$(Drive) = "d:" Then Beep : Exit Sub
ReDim Folders(250000) As DirData 'arbitrarily large
Folders(iPos).FileName = Drive
Do While Len(Folders(iPos).FileName)
temp$ = Dir$(Folders(iPos).FileName + "\*.*", %Normal + %SubDir, To tempINFO)
Do While Len(temp$)
tempINFO.FileName = Folders(iPos).FileName + "\" + tempINFO.FileName 'add full path to filename
If (tempINFO.FileAttributes And %File_Attribute_Directory) = 0 Then 'files
Incr FileCount
Kill tempINFO.FileName
Else 'folder
Incr FolderCount
Folders(FolderCount) = tempINFO
End If
temp$ = Dir$(Next, To tempINFO)
Loop
Incr iPos
Loop
For iPos = FolderCount To 1 Step -1 : RmDir Folders(iPos).FileName : Next i
End Sub
http://www.garybeene.com/sw/gbsnippets.htm