copying a file

Feb 13, 2010 at 1:27pm

copying a file

Dear Developers,

I’d like to copy files within an external and SDK gives some method to provide a plattform indipendent filehandling.

Easy steps:
1. open source file
2. open destination file
3. copy src to dst
4. check file length to ensure copy was successful

BUT….
it starts with the “path_opensysfile”-method. I do like this:

`if (path_opensysfile(srcPath->s_name, srcPath->s_name, &fSrc, READ_PERM)) {
object_error((t_object *)x, “error opening %s”, srcPath->s_name);
outlet_int(x->out, -1);
return;

}`
srcPath is a symbol I pass from my patch – under windows it look like:
“C:/Dokumente und Einstellungen/bla/Desktop/audios_to_copy/1.5.1 anFile.wav”
OK, I should pass the name as well. I tried that, nothing works.
Do I have to use somthing like this
path_nameconform(srcPath->s_name, fromConform, PATH_STYLE_NATIVE, PATH_TYPE_PATH);
??? and then give the fromConform as parameter???
I thought I am inside the max-world so I dont have to change the path.
My second question is:
How can I convert the char* of the symbol to an short. The documentation says it needs a short for the PATH ID… what is that?
(short)srcPath->s_name – didnt do it.

step 2:
I guess the problem is the same… path/name-handling
path_createsysfile(dstPath->s_name, (short)dstPath->s_name, type, &fDst);
The external cannot create a new file in realtime. Compiler-output is fine (except the short-casting).

step 3 – the copy process:
I found two relevant methods:
this is more elegant:
long ret = sysfile_spoolcopy(fSrc, fDst, 0);
And:
path_copyfile(srcPath->s_name, srcName->s_name, dstPath->s_name, dstName->s_name)

Still: if I could resolve problem 1, this one is obsolet.

step 4 – checking the copied file:
My simple idea was:

long sizeDst;
long sizeSrc;
sysfile_geteof(fDst, &sizeDst);
sysfile_geteof(fSrc, &sizeSrc);
if(sizeDst != sizeSrc){
//something went wrong
}

Well, I think I missed some very basic max-sdk knowledge or the solution is very simlpe.
I would be thankful if anyone can help.

Best,
Johannes

#48471
Feb 13, 2010 at 7:58pm

Here is the source code for an object which can copy files or folders on the file-system. Perhaps examining this code will help:

http://github.com/tap/JamomaModular/blob/master/implementations/MaxMSP/jcom.folder/jcom.folder.cpp

Cheers

#174308
Feb 14, 2010 at 4:42pm

Hi Timothy,

that helped a lot! I missed the path_frompathname – method! It is great – even special characters are supported.
Thanks!

Best
Johannes

#174309

You must be logged in to reply to this topic.