Copy folder problem

  • Thread starter Thread starter Simon Abolnar
  • Start date Start date
S

Simon Abolnar

I am working on problem of coping folder.

I am using Windows XP/VB.Net 2003

I know how to do it with FileSystemObject, but I would like to have copy
dialog between operation like it is in windows explorer.
Is it possible to do this with System.IO (framework)?

I tried to use SHFileOperation(SHFileOP), but something is wrong.

After setting SHFileOp structure like

With SHFileOp
.wFunc = FO_COPY
.pFrom = "C:\Temp" & Chr(0) & Chr(0)
.pTo = "C:\Backup" & Chr(0) & Chr(0)
.fFlags = FOF_SIMPLEPROGRESS
End With

my program stop with:

An unhandled exception of type 'System.NullReferenceException' occurred in
xxx.exe
Additional information: Object reference not set to an instance of an
object.

I don't know where is the problem.

Thanks all for help!!!

Simon
 
Hi,

API Declare
<DllImport("shell32.dll", entrypoint:="SHFileOperationA", _

setlasterror:=True, CharSet:=CharSet.Auto, exactspelling:=True, _

CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function SHFileOperation(ByRef lpFileOp As SHFILEOPSTRUCT) As
Integer

End Function



Structure



Structure SHFILEOPSTRUCT

Dim hwnd As Integer

Dim wFunc As Integer

Dim pFrom As String

Dim pTo As String

Dim fFlags As Short

Dim fAnyOperationsAborted As Integer

Dim hNameMappings As Integer

Dim lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS

End Structure



How To Use



Const FO_COPY = &H2

Const FOF_SIMPLEPROGRESS = &H100 ' means don't show names of files

Dim foCopy As SHFILEOPSTRUCT

With foCopy

.wFunc = FO_COPY

.pFrom = "C:\Temp" & Chr(0) & Chr(0)

.pTo = "C:\Backup" & Chr(0) & Chr(0)

.fFlags = FOF_SIMPLEPROGRESS

End With

SHFileOperation(foCopy)

Ken
 
Back
Top