copying folders using SHFileOperationA

For questions and postings not covered by the other forums
User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

copying folders using SHFileOperationA

Postby ghosttie » Tue Oct 11, 2011 8:00 am

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?
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

torrie
Posts: 92
Joined: Fri Aug 14, 2009 11:24 am

Re: copying folders using SHFileOperationA

Postby torrie » Tue Oct 11, 2011 8:51 am

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.

User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

Re: copying folders using SHFileOperationA

Postby ghosttie » Tue Oct 11, 2011 9:02 am

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.
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

allistar
Posts: 156
Joined: Fri Aug 14, 2009 11:02 am
Location: Mount Maunganui, Tauranga

Re: copying folders using SHFileOperationA

Postby allistar » Tue Oct 11, 2011 11:52 am

An external function that does he recursive copy would do the job nicely.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 13 guests

cron