1

私は簡単なコードを持っています:

NSFileManager *fileManager = [NSFileManager defaultManager];

if (!fileManager) NSLog(@"Manager doesn't exist!");

if(![fileManager fileExistsAtPath:destString]) {
    if (![fileManager createDirectoryAtPath:destString withIntermediateDirectories:YES attributes:nil error:&error]){
        NSLog(@"%@", [error localizedFailureReason]);
    }
}
else NSLog(@"Exists!");

vars:

destString = file://localhost/Users/SOMEUSER/Desktop/NEWFOLDER/

フォルダを作成しようとすると、プログラムは「存在します」と書き込みますが、デスクトップには存在しません。fileExistsAtPathを削除すると、エラーは発生しませんが、ディレクトリも発生しません。Thx 4返信!

4

1 に答える 1

4

-createDirectoryAtPath:withIntermediateDirectories:attributes:error:作成するパスを、ファイルのURLスタイルの文字列としてではなく、UNIXスタイルのパス文字列として取得します。つまり、のような文字列を渡します/Users/SOMEUSER/Desktop/NEWFOLDER/

または、URLスタイルの文字列を処理している場合は、-createDirectoryAtURL:withIntermediateDirectories:attributes:error:代わりに使用に切り替えてNSURL、文字列からを作成できます。

于 2013-02-13T09:58:25.760 に答える