macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

isDeletableFileAtPath:

パスで指定されるファイルは削除できるかを返します
-(BOOL)isDeletableFileAtPath:(NSString *)path:

解説

パスで指定されるファイルは削除できるかを返します。
指定したパスがシンボリックリンク(ファイルエイリアス)なら、そのファイルを削除できるかを返します。
実際に削除するためには、パスで指定されるファイルの親ディレクトリ(フォルダ)は書き込み可能でないといけません。
パスがディレクトリ(フォルダ)なら、その中に含まれるファイルも全て削除可能でないといけません。

返り値

( BOOL )

YES/NO

引数

( NSString * )path

パス

クラス

NSFileManager

Instance Methods

使用可能

10.0

参照

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSString *str = @"~/";
NSFileManager *myFile = [ NSFileManager defaultManager];
//ファイル属性
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
            [NSDate date],NSFileModificationDate,
            @"owner",@"NSFileOwnerAccountName",
            @"group",@"NSFileGroupOwnerAccountName",
            nil,@"NSFilePosixPermissions",
            [NSNumber numberWithBool:YES],@"NSFileExtensionHidden",
            nil];
//書き込むデータ
NSString *str2 = @"Mutable data";

NSMutableData *dat1 = [[[NSMutableData alloc] autorelease] initWithCapacity:1];
[dat1 appendBytes:[str2 cString] length:[str2 cStringLength]];

[myFile changeCurrentDirectoryPath:[str stringByExpandingTildeInPath]];
//ファイル作成
[myFile createFileAtPath:@"createdNewFile" contents:dat1 attributes:dic];

if ([myFile isDeletableFileAtPath:@"createdNewFile"]){
    NSLog(@"YES");
    }else{
    NSLog(@"NO");
    }


}

@end