Y
yxq
Hello,
My system is Windows XP + SP2, please try the code below,
the code will copy all file to another directory.
Please create a new directory(C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}),
copy some files into directory.
////////////////////////////////////////////////////
Invoke the function(the code below successful):
If FileOperate.ShellCopy("C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}\",
"c:\test", False, False) <> 0 Then
MessageBox.Show("fail")
Else
MessageBox.Show("done")
End If
///////////////////////////////////////////////////////
The code below is fail
If FileOperate.ShellCopy("C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}",
"c:\test", False, False) <> 0 Then
MessageBox.Show("fail")
Else
MessageBox.Show("done")
End If
Can anyone tell why?????
The class is below
//////////////////////////////////////////////////////////////////////////
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 Short = &H40S
Private Const FOF_NOCONFIRMATION = &H10S
Private Const FO_MOVE = &H1S
Private Const FO_COPY = &H2S
Private Const FOF_NOERRORUI = &H400S
Private Const FOF_SILENT = &H4S
Private Declare Function SHFileOperation Lib "shell32.dll" Alias
"SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
Private Shared SHFileOp As SHFILEOPSTRUCT
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(SourcePath.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
My system is Windows XP + SP2, please try the code below,
the code will copy all file to another directory.
Please create a new directory(C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}),
copy some files into directory.
////////////////////////////////////////////////////
Invoke the function(the code below successful):
If FileOperate.ShellCopy("C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}\",
"c:\test", False, False) <> 0 Then
MessageBox.Show("fail")
Else
MessageBox.Show("done")
End If
///////////////////////////////////////////////////////
The code below is fail
If FileOperate.ShellCopy("C:\{91A9BEC9-ED3C-4382-8615-BC0B466D2936}",
"c:\test", False, False) <> 0 Then
MessageBox.Show("fail")
Else
MessageBox.Show("done")
End If
Can anyone tell why?????
The class is below
//////////////////////////////////////////////////////////////////////////
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 Short = &H40S
Private Const FOF_NOCONFIRMATION = &H10S
Private Const FO_MOVE = &H1S
Private Const FO_COPY = &H2S
Private Const FOF_NOERRORUI = &H400S
Private Const FOF_SILENT = &H4S
Private Declare Function SHFileOperation Lib "shell32.dll" Alias
"SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
Private Shared SHFileOp As SHFILEOPSTRUCT
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(SourcePath.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