[comp.sys.mac.programmer] help with PBCatMove call

henges@ingr.com (John Hengesbach) (02/21/90)

I am trying to move a file from one directory to another.  I am trying to
do this using THINK C 4.0.  This seemingly should be easy...so why am I
having so much trouble? I sure could use a helping hand.

The rename() library function works if you are just trying to rename it.
That was the first stumbling block.  So into IM I go and I find that
there are several rename/move file functions.  Vol IV p153-4 gives me
PBRename and PBHRename.  However, these appear to be rename only type
functions, i.e. no actual move.  On page 157, we find PBCatMove.  This
appears to be what I want.  Great!!

I've tried this many times an so far only seem to get error -43 (file not
found) with any of the different things I've tried.

Basically, I have the directory ID of the current_dir and of the
new_dir which I got from calls to either PBGetCatInfo or PBDirCreate
(depending on whether they were previously existing).  I also have the 
VRefNum which I got from the same call.  The current default directory
is set to the current_dir.  I then proceed to call PBCatMove
with the following arguments:

	.ioCompletion	==> pass in a (long)0
	.ioNamePtr	==> pass in a ptr to a pascal string of orig name
				(without any colons, etc)
	.ioVRefNum	==> pass in value received from call to PBGetCatinfo
				on the current_directory
	.ioNewName	==> pass in a ptr to a pascal string of new name
				(without any colons, etc)
	.ioNewDirID	==> pass in value received from call to PBGetCatInfo
				for new_dir
	.ioDirID	==> pass in value received from call to PBGetCatInfo
				for current_dir

The relevant code snippet follows:


    char file_name[256];
    char new_name[256];
    char old_name[256];
    long current_id;
    long new_id;
    int	results;
    CInfoPBRec info_rec;
    CMovePBRec move_rec;
    
    printf("name to move: %s DirID: %ld VRefNum: %d NewDirID: %ld\n",
           file_name,current_id,info_rec.hFileInfo.ioVRefNum,new_id);
    sprintf(old_name,"%s",file_name);
    CtoPstr(old_name);
    /* Since the destination directory is a subdirectory of current_directory,
       I tried both with and without : in the next line below to no avail.
                      v  */
    sprintf(new_name,":%s",file_name);
    CtoPstr(new_name);
    
    move_rec.ioCompletion = NULL;
    move_rec.ioNamePtr = (StringPtr)old_name;
    move_rec.ioVRefNum = info_rec.hFileInfo.ioVRefNum;
    move_rec.ioNewName = (StringPtr)new_name;
    move_rec.ioNewDirID = new_id;
    move_rec.ioDirID = current_id;
    results = PBCatMove(&move_rec,0);
    printf("mode res: %d\n",results);	/* results is always -43 */

John (why are easy things always the hardest?) Hengesbach
-- 
John Hengesbach
   ..!uunet!ingr!henges			Intergraph
   henges@ingr.com 			Huntsville, Alabama 35894-0001
   (205)730-2020