如何使用 NSFileManager 重命名文件 [英] How to rename a file using NSFileManager

查看:79
本文介绍了如何使用 NSFileManager 重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文档目录中有一个名为 a.caf 的文件.我想在用户输入 UITextField 并按下更改时重命名它(在 UITextField 中输入的文本应该是新文件名).

I have a single file named a.caf in the documents directory. I would like to rename it when user types into a UITextField and presses change (the text entered in the UITextField should be the new filename).

我该怎么做?

推荐答案

您可以使用 moveItemAtPath.

NSError * err = NULL;
NSFileManager * fm = [[NSFileManager alloc] init];
BOOL result = [fm moveItemAtPath:@"/tmp/test.tt" toPath:@"/tmp/dstpath.tt" error:&err];
if(!result)
    NSLog(@"Error: %@", err);
[fm release];

这篇关于如何使用 NSFileManager 重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆