home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Snippets / PathFromFSSpec / PathFromFSSpec.p next >
Encoding:
Text File  |  1994-05-03  |  2.3 KB  |  52 lines  |  [TEXT/R*ch]

  1. This of course    }
  2. {requires system seven or better because of the use of the alias manager  }
  3. { Don't forget to dispose the handle when you are done with it.           }
  4. {-------------------------------------------------------------------------}
  5. {$PUSH}
  6. {$-R}
  7.  function PathNameFromFSSpec (var theFile: FSSpec): Handle;
  8.   var
  9.    i: AliasInfoType;
  10.    theStr: STR63;
  11.    h: Handle;
  12.    oe: OSErr;
  13.    alias: AliasHandle;
  14.    theSize: longint;
  15.  begin
  16.   PathNameFromFSSpec := nil;
  17.   oe := NewAlias(nil, theFile, alias);          {create a temporary alias}
  18.   if alias = nil then                                       {if nil exit }
  19.    exit(PathNameFromFSSpec);
  20.  
  21.   h := NewHandle(0);
  22.   if h = nil then                                          {if nil exit. }
  23.    exit(PathNameFromFSSpec);
  24.  
  25.   i := asiAliasName;                       { set the index to the Parent }
  26.   if GetAliasInfo(alias, i, thestr) = noerr then     {get The parentName }
  27.    begin                                     {returns error if bad alias }
  28.     while thestr <> '' do      { will be '' when done traversing the path}
  29.      begin
  30.       theSize := longint(thestr[0]) + 1;       
  31.       thestr[0] := ':';  { use the size byte to store the colon. aux='/' }
  32.                                                 { Let Munger do the work }
  33.       theSize := Munger(h, 0, nil, 0, @thestr, thesize); 
  34.       i := i + asiParentName;           {set the index to the next parent}
  35.       oe := GetAliasInfo(alias, i, thestr);          {get the parentName }
  36.      end;
  37.                                                     {get the Volume Name }
  38.     oe := GetAliasInfo(alias, asiVolumeName, thestr);
  39.     theSize := longint(thestr[0]);
  40.     theSize := Munger(h, 0, nil, 0, Ptr(ord(@theStr) + 1), theSize);
  41.  
  42.     PathNameFromFSSpec := h;             {return the newly created handle}
  43.    end;
  44.   DisposeHandle(Handle(alias));
  45.  end;
  46. {$POP}
  47.  
  48.  
  49. Matt
  50.  
  51.  
  52.