Copy folder problem

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
 
K

Ken Tucker [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top