简体   繁体   English

无法读取FSRef中带有特殊字符的路径

[英]Unable to read a path with special characters in FSRef

With this code I am trying to get the path in const char *pathPtr from fsRefAEDesc. 通过此代码,我试图从fsRefAEDesc获取const char * pathPtr中的路径。 It gives the correct name and path if there are no special characters in the name of file which is there in fsRefAEDesc. 如果文件名中没有特殊字符(fsRefAEDesc中存在),它将给出正确的名称和路径。 Now if path has some special characters /Users/XYZ/.rtf I don't get a correct fsRef from AEGetDescData(). 现在,如果path具有一些特殊字符/Users/XYZ/.rtf,我不会从AEGetDescData()获得正确的fsRef。 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*)(&fsRef), 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? 例如,如果插入CFShow(macPath) ,您是否在调试日志中看到正确的路径? If so, then you are not passing the right encoding to CFStringGetCStringPtr . 如果是这样,则您没有将正确的编码传递给CFStringGetCStringPtr Use UTF-8. 使用UTF-8。

Also tried this for gotURLRef but I got the same on my console ie "/Users/Manish/Desktop/\➤\©\☚.png" 还尝试了getURLRef,但是我在控制台上得到了相同的信息,即“ /Users/Manish/Desktop/\➤\©\☚.png”

The Unicode escape sequence is what you get when going through CFURL calls. Unicode转义序列是通过CFURL调用时得到的。 URL has very limited character range. URL的字符范围非常有限

You can try FSRefMakePath . 您可以尝试FSRefMakePath It will get you UTF8 encoded path from a FSRef. 它将从FSRef获得UTF8编码的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM