【发布时间】:2013-01-11 15:12:39
【问题描述】:
我已经看到这个问题被问了几次,但到目前为止我无法使用任何帖子解决方案取得成功。我想要做的是重命名应用程序本地存储中的文件(对于 Obj-c 来说也是一种新的)。我能够检索旧路径并创建新路径,但是我必须写什么才能真正更改文件名?
到目前为止,我所拥有的是:
- (void) setPDFName:(NSString*)name{
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString* initPath = [NSString stringWithFormat:@"%@/%@",[dirPaths objectAtIndex:0], @"newPDF.pdf"];
NSString *newPath = [[NSString stringWithFormat:@"%@/%@",
[initPath stringByDeletingLastPathComponent], name]
stringByAppendingPathExtension:[initPath pathExtension]];
}
【问题讨论】:
-
所以您想将
Documents目录中的newPDF.pdf重命名为传递给该方法的任何内容? -
正确!想要做到这一点。
-
xcode 只是一个 IDE。我实际上被标题和标签激怒了,起初我以为你想重命名/重构方法名称 setPDFName。
标签: objective-c