ドキュメント ディレクトリにa.cafという名前のファイルが 1 つあります。UITextField
ユーザーが aに入力して変更を押したときに名前を変更したいと思います (に入力されたテキストUITextField
は新しいファイル名である必要があります)。
これどうやってするの?
ドキュメント ディレクトリにa.cafという名前のファイルが 1 つあります。UITextField
ユーザーが aに入力して変更を押したときに名前を変更したいと思います (に入力されたテキストUITextField
は新しいファイル名である必要があります)。
これどうやってするの?
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];
この質問を最新の状態に保つために、 Swiftバージョンも追加しています。
let documentDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String
let originPath = documentDirectory.stringByAppendingPathComponent("/tmp/a.caf")
let destinationPath = documentDirectory.stringByAppendingPathComponent("/tmp/xyz.caf")
var moveError: NSError?
if !manager.moveItemAtPath(originPath, toPath: destinationPath, error: &moveError) {
println(moveError!.localizedDescription)
}