Even worse: Any one know how to keep SHFileOperation from popping up the confirmation dialog ?? I know it's a flag of some sort but can't find it.
VB Code:
'In general section
Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpPathName As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Private Const FO_DELETE = &H3
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Sub Command1_Click()
If FolderExist("c:\bob") = True Then
MsgBox "it's there"
Else
MsgBox "Boo-Hoo"
End If
End Sub
Public Function FolderExist(sFolderPath) As Boolean
'KPD-Team 1998
'URL: [url]http://www.allapi.net/[/url]
Dim Security As SECURITY_ATTRIBUTES
'Create a directory
Ret& = CreateDirectory(sFolderPath, Security)
'If CreateDirectory returns 0, the function has failed
If Ret& = 0 Then
FolderExist = True
Else
Dim SHDirOp As SHFILEOPSTRUCT
With SHDirOp
.wFunc = FO_DELETE
.pFrom = sFolderPath
End With
'Delete the directory
SHFileOperation SHDirOp
FolderExist = False
End If
End Function