Page 1 of 1

copying folders using SHFileOperationA

Posted: Tue Oct 11, 2011 8:00 am
by ghosttie
I'm trying to add functionality to copy folders. I don't think there's a native way of doing this in JADE so I'm using the SHFileOperationA API call:

Code: Select all

copyFolderClient(pS_Source, pS_Dest : String) : Boolean; constants FO_COPY : Binary = #2.Binary; HWnd : Binary = #[00 00 00 00]; DoubleNull : Binary = #[00 00]; Flags : Binary = #[00 00]; Aborted : Binary = #[00 00]; HNameMaps : Binary = #[00 00 00 00]; SProgress : Binary = #[00]; vars binOp : Binary; begin binOp := HWnd & FO_COPY & pS_Source.Binary & DoubleNull & pS_Dest.Binary & DoubleNull & Flags & Aborted & HNameMaps & SProgress; return call shFileOperation(binOp).Boolean; end;
The problem I have is that every time I call this, JADE crashes.

I'm pretty sure the problem is that I don't have the data fields right for the SHFILEOPSTRUCT, but I can't see what I'm doing wrong.

Has anyone successfully used the SHFileOperationA API call in JADE?

Re: copying folders using SHFileOperationA

Posted: Tue Oct 11, 2011 8:51 am
by torrie
Hi

I've not used this function, but the issue appears to be the way you are building up the struct as a binary.

In Source and Destination properties (and the progress header) in the struct are LPCTSTR properties. Windows is expecting a memory address (not the actual string.)

If running on Fat client or the server you can build up the struct as

{code}
binOp := HWnd & FO_COPY & pS_Source.bufferAddress & pS_Dest.bufferAddress & Flags & Aborted & HNameMaps & SProgress;
{code}

Note, the pS_Source and pS_Dest would need to be terminated with double nulls. You should probably do the same with the SProgress variable as well.

If you're using a thin client, then you can't access the memory address for the string (as it's stored in memory on the Application Server.)

We've got code that copies folders and we use the FileFolder::files property to enumerate the files in a folder and copy these individually. You can use the copyFile API function to copy an individual file (http://msdn.microsoft.com/en-us/library ... S.85).aspx) I don't know if this API works with a folder path.

Re: copying folders using SHFileOperationA

Posted: Tue Oct 11, 2011 9:02 am
by ghosttie
Thanks, I didn't realize it was expecting the addresses of the strings.

I guess I can't use SHFileOperationA, since we're using thin client for most things.

I was hoping to avoid copying the files and subfolders one at a time because I assumed it would be a lot slower than a one-shot API call.

Re: copying folders using SHFileOperationA

Posted: Tue Oct 11, 2011 11:52 am
by allistar
An external function that does he recursive copy would do the job nicely.