Here is an alternate approach. Create a C DLL with this exported function:
extern "C" __declspec(dllexport) void MoveDirectory(
const wchar_t* source, const wchar_t* destination)
{
SHFILEOPSTRUCT fop = {};
fop.wFunc = FO_MOVE;
fop.pFrom = source;
fop.pTo = destination;
SHFileOperation (&fop);
}
And P/Invoke it from C#:
[DllImport("SomeLib.dll", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl)]
public static extern void MoveDirectory(string source, string destination);
static void Main()
{
MoveDirectory("c:\\abc\0", "d:\\abc\0");
}
Notice the extra
NULL
s I added to the string. That is required and is not a typo.