开发者

Unable to read a path with special characters in FSRef

开发者 https://www.devze.com 2023-01-04 03:28 出处:网络
With this code I am trying to get the path in const char *pathPtr fromfsRefAEDesc. It gives the correct name and path if there are no special characters in the name of file which is there infsRefAEDes

With this code I am trying to get the path in const char *pathPtr from fsRefAEDesc. It gives the correct name and path if there are no special characters in the name of file which is there in fsRefAEDesc. Now if path has some special characters /Users/XYZ/.rtf I don't get a correct fsRef from AEGetDescData(). I believe it has some thing to do with Encoding and tried some them but could make it work.

FSRef fsRef;
//AEDesc fsRefAEDesc; //comes from some where. 

status = AEGetDescData( &fsRefAEDesc, (void*)(&fsRe开发者_如何学Pythonf), sizeof(FSRef));
//OSErr result = FSMakeFSRefUnicode(&fsRef, 1024, (UniCharPtr)(&fsRef),   kTextEncodingUnknown, &fileRef);
AEDisposeDesc( &fsRefAEDesc );

 CFURLRef* gotURLRef = CFURLCreateFromFSRef(NULL, &fsRef);
 CFStringRef macPath = CFURLCopyFileSystemPath(gotURLRef,  kCFURLPOSIXPathStyle);

 const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding());

Is there is any way to read such paths?


At what point in your code does the problem occur? For instance, if you insert CFShow(macPath), do you see the right path in the debug log? If so, then you are not passing the right encoding to CFStringGetCStringPtr. Use UTF-8.


Also tried this for gotURLRef but I got the same on my console i.e. "/Users/Manish/Desktop/\u27a4\u00a9\u261a.png"

The Unicode escape sequence is what you get when going through CFURL calls. URL has very limited character range.

You can try FSRefMakePath. It will get you UTF8 encoded path from a FSRef.

0

精彩评论

暂无评论...
验证码 换一张
取 消