home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / mac / programm / 15522 < prev    next >
Encoding:
Text File  |  1992-09-15  |  3.4 KB  |  116 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!gumby!destroyer!ncar!roke.rap.ucar.edu!tres
  3. From: tres@roke.rap.ucar.edu (Tres Hofmeister)
  4. Subject: File Manager Question
  5. Message-ID: <1992Sep15.210718.25918@ncar.ucar.edu>
  6. Keywords: PBGetCatInfo, PBSetCatInfo
  7. Sender: news@ncar.ucar.edu (USENET Maintenance)
  8. Organization: National Center for Atmospheric Research / RAP
  9. Distribution: usa
  10. Date: Tue, 15 Sep 1992 21:07:18 GMT
  11. Lines: 103
  12.  
  13.  
  14.     I'm having trouble understanding why a call to PBSetCatInfo is
  15. failing.  I'm a beginning Macintosh programmer, and would appreciate
  16. any help offered, especially suggestions on more effective solutions
  17. to this problem, or improvements.
  18.  
  19.     What I'm trying to do here is to update the modification time
  20. of the parent directory of a file.  As this will eventually be
  21. converted into an XCMD, I'm using the full pathname of the file,
  22. which is easy to come by in HyperCard.  In this test program the
  23. filename is a constant, but later it will be passed in as an argument
  24. to the XCMD.
  25.  
  26.     Rather than parsing the pathname, I thought I could grab the
  27. parent directory's directory ID from the ioDrParID field of the
  28. parameter block, call PBGetCatInfo again to get information on the
  29. parent, then set the parent's modification date with PBSetCatInfo.
  30.  
  31.     The problem is that the call to PBSetCatInfo is failing with a
  32. "file not found" error.  I'm not sure why this should be when prior
  33. and subsequent calls to PBGetCatInfo using the same parameter block
  34. work fine.  Everything else seems to work fine.
  35.  
  36.     Here's the code:
  37.  
  38. #include <string.h>
  39. #include <stdio.h>
  40.  
  41. main()
  42. {
  43.     CInfoPBRec    info;
  44.     long        parDirID;
  45.     Str255        name;
  46.  
  47.     /* Zero struct */
  48.     memset(&info, 0, sizeof(info));
  49.  
  50.     info.dirInfo.ioNamePtr =
  51.         CtoPstr("Quantum 105:Desktop Folder:/tmp:Junk");
  52.  
  53.     /* Get file information */
  54.     printf("PBGetCatInfo result: file: %i\n",
  55.         PBGetCatInfo(&info, FALSE));
  56.     printf("Filename: \"%#s\"\n", info.dirInfo.ioNamePtr);
  57.  
  58.     /* Save parent directory ID */
  59.     parDirID = info.dirInfo.ioDrParID;
  60.  
  61.     /* Reset the CInfoPBRec struct for the parent directory */
  62.     memset(&info, 0, sizeof(info));
  63.     info.dirInfo.ioNamePtr = name;
  64.     info.dirInfo.ioDrDirID = parDirID;
  65.     info.dirInfo.ioFDirIndex = -1;
  66.  
  67.     /* Get parent directory information */
  68.     printf("PBGetCatInfo result: folder: %i\n",
  69.         PBGetCatInfo(&info, FALSE));
  70.     printf("Folder Name: \"%#s\"\n", info.dirInfo.ioNamePtr);
  71.  
  72.     printf("Modification date before: %lu\n",
  73.         info.dirInfo.ioDrMdDat);
  74.  
  75.     /* Set modification time to current time */
  76.     GetDateTime(&info.dirInfo.ioDrMdDat);
  77.  
  78.     /* Set folder information */
  79.     printf("PBSetCatInfo result = %i\n",
  80.         PBSetCatInfo(&info, FALSE));
  81.  
  82.     /* Try again */
  83.     printf("PBGetCatInfo result: file: %i\n",
  84.         PBGetCatInfo(&info, FALSE));
  85.  
  86.     printf("Modification date after: %lu\n",
  87.         info.dirInfo.ioDrMdDat);
  88. }
  89.  
  90.  
  91.     And here's the output from the program:
  92.  
  93. PBGetCatInfo result: file: 0
  94. Filename: "Quantum 105:Desktop Folder:/tmp:Junk"
  95. PBGetCatInfo result: folder: 0
  96. Folder Name: "/tmp"
  97. Modification date before: 2799405218
  98. PBSetCatInfo result = -43
  99. PBGetCatInfo result: file: 0
  100. Modification date after: 2799405218
  101.  
  102.  
  103.     Error -43 is the "file not found" error.  What am I doing
  104. wrong?  Also, is there an "official" Macintosh way to zero a struct,
  105. rather than using memset()?
  106.  
  107.     I'm using THINK C 5.x.  The entire point of this exercise is
  108. to get the Finder to update the icon on a file who's creator has been
  109. changed.
  110.  
  111.     Many thanks, in advance.
  112.  
  113. --
  114. Tres Hofmeister
  115. tres@ncar.ucar.edu
  116.