Sorry, the io.file.delete works well, but the API below for x86 will not
work on x64, how to change the API to x64?
//////////////////////////////////////////////////////////////////////////////////////
Public Class FileOperate
Private Structure SHFILEOPSTRUCT
Dim hWnd As Integer
Dim wFunc As Integer
Dim pFrom As String
Dim pTo As String
Dim fFlags As Short
Dim fAborted As Boolean
Dim hNameMaps As Integer
Dim sProgress As String
End Structure
Private Const FO_DELETE As Short = &H3S
Private Const FOF_ALLOWUNDO As Int16 = &H40S
Private Const FOF_NOCONFIRMATION As Int16 = &H10S
Private Const FO_MOVE As Int16 = &H1S
Private Const FO_COPY As Int16 = &H2S
Private Const FOF_NOERRORUI As Int16 = &H400S
Private Const FOF_SILENT As Int16 = &H4S
Private Declare Function SHFileOperation Lib "shell32.dll" Alias
"SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
Private Shared SHFileOp As SHFILEOPSTRUCT
Public Shared Function ShellDirectDelete(ByRef sFile As String, Optional
ByVal ShowProgress As Boolean = True) As Int16
sFile = sFile & Chr(0)
With SHFileOp
.fAborted = True
.wFunc = FO_DELETE
.pFrom = sFile
If ShowProgress = True Then
.fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI
Else
.fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI +
FOF_SILENT
End If
End With
Return SHFileOperation(SHFileOp)
End Function
Public Shared Function ShellDelToRecycled(ByRef sFile As String,
Optional ByVal ShowProgress As Boolean = True) As Int16
sFile = sFile & Chr(0)
With SHFileOp
.fAborted = True
.wFunc = FO_DELETE
.pFrom = sFile
If ShowProgress = True Then
.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION + FOF_NOERRORUI
Else
.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION + FOF_NOERRORUI
+ FOF_SILENT
End If
End With
Return SHFileOperation(SHFileOp)
End Function
Public Shared Function ShellMove(ByVal SourcePath As String, ByVal
DsintedPath As String, Optional ByVal ShowProgress As Boolean = True, _
Optional ByVal MoveEntireDir As Boolean = True) As Int16
If IO.Directory.Exists(DsintedPath) = False Then
IO.Directory.CreateDirectory(DsintedPath)
Application.DoEvents()
If SourcePath.EndsWith("\") Then
SourcePath.Remove(SourcePath.Length - 1, 1)
If DsintedPath.EndsWith("\") Then
DsintedPath.Remove(DsintedPath.Length - 1, 1)
With SHFileOp
.fAborted = True
.wFunc = FO_MOVE
If MoveEntireDir = True Then
.pFrom = SourcePath & Chr(0)
Else
.pFrom = SourcePath & "\*.*"
End If
.pTo = DsintedPath
If ShowProgress = True Then
.fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI
Else
.fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI +
FOF_SILENT
End If
End With
Return SHFileOperation(SHFileOp)
End Function
Public Shared Function ShellCopy(ByVal SourcePath As String, ByVal
DsintedPath As String, Optional ByVal ShowProgress As Boolean = True, _
Optional ByVal CopyEntireDir As Boolean = True) As Int16
If IO.Directory.Exists(DsintedPath) = False Then
IO.Directory.CreateDirectory(DsintedPath)
Application.DoEvents()
If SourcePath.EndsWith("\") Then
SourcePath.Remove(SourcePath.Length - 1, 1)
If DsintedPath.EndsWith("\") Then
DsintedPath.Remove(DsintedPath.Length - 1, 1)
With SHFileOp
.fAborted = True
.wFunc = FO_COPY
If CopyEntireDir = True Then
.pFrom = SourcePath & Chr(0)
Else
.pFrom = SourcePath & "\*.*"
End If
.pTo = DsintedPath
If ShowProgress = True Then
.fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI
Else
.fFlags = 0 + FOF_NOCONFIRMATION + FOF_NOERRORUI +
FOF_SILENT
End If
End With
Return SHFileOperation(SHFileOp)
End Function
End Class
"yxq" <ga***@163.netдÈëÏûÏ¢ÐÂÎÅ:Oh**************@TK2MSF TNGP05.phx.gbl...
Yes, i have the permission(Right-Click the exe file, choose the Run as
Administrator), even i closed the UAC function.
"Ken Tucker [MVP]" <vb***@bellsouth.net>
??????:72**********************************@micros oft.com...
>Hi,
There were a lot of security changes in Vista. Are you sure
you have permission to delete the file?
http://msdn2.microsoft.com/en-us/library/aa480150.aspx
Ken
---------------------
"yxq" <ga***@163.netwrote in message
news:u4**************@TK2MSFTNGP04.phx.gbl...
>>Hello,
The File.Delete(VS2005) function can not delete file on Vista-64bit,
why?
And, what changes of API between 32-bit and 64-bit?
Thank you