在iPhone上创建一个文件夹。

4

我想知道如何在指定路径上创建一个目录。 我使用了"system("目录的路径");",这在模拟器上运行良好,但在设备上不起作用。


你实际上想做什么? - bbum
实际上我想使用这个命令“chmod + x /目录路径/”。所以我使用System(“chmod +x /文件路径/”); 这在模拟器上运行良好,但在设备上不起作用。 - Mitali
2个回答

8
要在应用程序库目录中创建一个新的目录,请使用以下方法...
// Generate the path to the new directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *newDirectory = [NSString stringWithFormat:@"%@/new", [paths objectAtIndex:0]];

// Check if the directory already exists
if (![[NSFileManager defaultManager] fileExistsAtPath:newDirectory]) {
    // Directory does not exist so create it
    [[NSFileManager defaultManager] createDirectoryAtPath:newDirectory withIntermediateDirectories:YES attributes:nil error:nil];
}

你能指导我如何将数据保存在特定的目录中吗? - user1573321
请查看https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html#//apple_ref/occ/instm/NSData/writeToFile:atomically:。 - AlBeebe

2

createDirectoryAtPath:attributes: 方法已经被弃用。

请使用 createDirectoryAtPath:withIntermediateDirectories:attributes:error: 代替。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接