Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Extract fuul file name from OpenDialog...

22 views
Skip to first unread message

Fonarix

unread,
Jan 15, 2007, 10:06:36 AM1/15/07
to

"""Gregory Weston писал(а):
"""
> In article <1168856518.5...@11g2000cwr.googlegroups.com>,
> "Fonarix" <fon...@ukr.net> wrote:
>
> > Greetings!
> >
> > I'm trying open file with open dialog NavGetFile and extract full file
> > name...
> >
> >
> > anErr = AEGetNthPtr(&(reply.selection), index,
> > typeFSS, &theKeyword,
> >
> > &actualType,&documentFSSpec,
> > sizeof(documentFSSpec),
> > &actualSize);
> >
> > documentFSSpec - returns too short name, and I have to get file name
> > full, more than 32 chars....
> >
> >
> > Thanks!
>
> First, you should ask future questions about programming in one of the
> comp.sys.mac.programmer.* groups. I've redirected follow-ups.
>
> Second, depending on how recent your minimum target OS version is, you
> should probably consider using NavCreateGetFileDialog, NavDialogRun and
> NavDialogGetReply to handle this. It's got more explicit support for
> modern FS features.
>
> Third, the FSSpec you're getting back through your current method should
> be valid despite potentially having an uglified name. You can probably
> ask for a file reference instead of the fsspec and then use that to
> retrieve the full name.
>
> Check <http://developer.apple.com/technotes/tn2002/tn2078.html> for more
> details and examples.
>
> --
> The best intentions in the world don't make a flawed argument magically valid.

Thanks for reply!

Crrently in code used NavGetFile (it's look like very old dialog
function...??)

>From FSSpec I get the only full path, but not file name:
FSRef fsRef;
CFURLRef URLRef;
OSErr oserr;
CFStringRef StringRef;
oserr = FSpMakeFSRef( &documentFSSpec, &fsRef );
URLRef = CFURLCreateFromFSRef(kCFAllocatorDefault, &fsRef);
StringRef = CFURLCopyFileSystemPath( URLRef, kCFURLPOSIXPathStyle
);
CFStringGetCString( StringRef, (char*)&theFile->FileName,
sizeof(theFile->FileName), kCFStringEncodingMacHFS );

Ok, I'll learn this issue later...

Thanks!

Sean McBride

unread,
Jan 15, 2007, 8:38:04 PM1/15/07
to
In article <1168873596.6...@s34g2000cwa.googlegroups.com>,
"Fonarix" <fon...@ukr.net> wrote:

> Thanks for reply!
>
> Crrently in code used NavGetFile (it's look like very old dialog
> function...??)
>
> >From FSSpec I get the only full path, but not file name:
> FSRef fsRef;
> CFURLRef URLRef;
> OSErr oserr;
> CFStringRef StringRef;
> oserr = FSpMakeFSRef( &documentFSSpec, &fsRef );
> URLRef = CFURLCreateFromFSRef(kCFAllocatorDefault, &fsRef);
> StringRef = CFURLCopyFileSystemPath( URLRef, kCFURLPOSIXPathStyle
> );
> CFStringGetCString( StringRef, (char*)&theFile->FileName,
> sizeof(theFile->FileName), kCFStringEncodingMacHFS );
>
> Ok, I'll learn this issue later...

You should use the newer Nav Serv APIs. Avoid any API that uses FSSpecs.

Gregory Weston

unread,
Jan 16, 2007, 7:40:27 AM1/16/07
to

> Crrently in code used NavGetFile (it's look like very old dialog
> function...??)

No, it's not VERY old. It's merely passe. StandardGetFile is very old.
SFGetFile is ancient.

>
> >From FSSpec I get the only full path, but not file name:
> FSRef fsRef;
> CFURLRef URLRef;
> OSErr oserr;
> CFStringRef StringRef;
> oserr = FSpMakeFSRef( &documentFSSpec, &fsRef );
> URLRef = CFURLCreateFromFSRef(kCFAllocatorDefault, &fsRef);
> StringRef = CFURLCopyFileSystemPath( URLRef, kCFURLPOSIXPathStyle
> );

Another thing you can do with a CFURLRef is extract the components of
its path as strings. CFURLCopyLastPathComponent() is the one you want
for just the leaf name.

Fonarix

unread,
Jan 16, 2007, 11:11:58 AM1/16/07
to
> --
> The best intentions in the world don't make a flawed argument magically valid.


Thanks for reply!
OS: 10.3.9+
There in code used only NavGetFile function.
I've used some code:


FSRef fsRef;
CFURLRef URLRef;
OSErr oserr;
CFStringRef StringRef;
oserr = FSpMakeFSRef( &documentFSSpec, &fsRef );
URLRef = CFURLCreateFromFSRef(kCFAllocatorDefault, &fsRef);
StringRef = CFURLCopyFileSystemPath( URLRef, kCFURLPOSIXPathStyle
);

CFStringGetCString( StringRef, (char*)&theFile->FileName,
sizeof(theFile->FileName), kCFStringEncodingMacHFS );

But I got full file name, is the way get only filename? Of course I
can parse it for "//".

Mach thanks!

0 new messages