【问题标题】:changecurrentdirectorypath changes the current path to null in objective cchangecurrentdirectorypath 在目标 c 中将当前路径更改为 null
【发布时间】:2015-12-05 06:20:52
【问题描述】:

我多次尝试将当前目录更改为/User/{username} 所以我可以在/User/{username}/ 目录中创建新文件夹。 我使用的代码是:

filemgr = [NSFileManager defaultManager];

currentpath = [filemgr currentDirectoryPath];

NSLog (@"from changing directory Current directory is %@", currentpath);

if ([filemgr changeCurrentDirectoryPath: @"/Users/"] == NO)
    NSLog (@"from changing directory Cannot change directory.");
else
    NSLog(@"directory changed is %@",currentpath);

currentpath = [filemgr currentDirectoryPath];

NSLog (@"directory after changed Current directory is %@", currentpath);

并得到如下输出:

2015-12-05 11:47:43.450 test2_Finder[970:33618] 从更改目录当前目录是 /Users/macbookpro/Library/Containers/com.eebs.Test2.test2-Finder/Data 2015-12-05 11:47:43.450 test2_Finder

[970:33618] 目录更改为 /Users/macbookpro/Library/Containers/com.eebs.Test2.test2-Finder/Data 2015-12-05 11:47:43.458 test2_Finder[970:33618] 更改后的目录 当前目录为 (null)

2015-12-05 11:47:43.458 test2_Finder[970:33618] - [FinderSync init] 从 /Users/macbookpro/Library/Developer/Xcode/DerivedData/Test2-hbxwqkjtnzaewlcisyxybyfbzefb/Build/Products/Debug/Test2 启动.app/Contents/PlugIns/test2_Finder.appex ; 11:47:39 编译

【问题讨论】:

  • 你称之为当前目录的东西是什么?更改当前目录是什么意思?
  • 当我使用 'BOOL isDir; NSFileManager *fileManager= [NSFileManager defaultManager]; if(![fileManager fileExistsAtPath:@"../Library/Java/folder1" isDirectory:&isDir]) if(![fileManager createDirectoryAtPath:@"../Library/Java/folder1" withIntermediateDirectories:YES 属性:nil 错误:NULL ]) NSLog(@"错误:创建文件夹失败 %@",@"/Library/Java/");'在 /Users/macbookpro/Library/Containers/com.eebs.Test2.test2-Finder/Data/file:/Library/Java 文件夹中创建一个文件夹我想要的是在 /User/macbookpro/java中创建一个文件夹>

标签: objective-c xcode macos finder


【解决方案1】:

终于得到了为用户目录创建文件夹的解决方案 比如 “/用户/macbookpro/文件夹” NSString *userPath=[NSOpenStepRootDirectory() stringByAppendingString:@"Users/"]; NSString *userPath1=[userPath stringByAppendingString:NSUserName()]; NSString *userPath2=[userPath1 stringByAppendingString:@"/folder/"]; if(![fileManager fileExistsAtPath:userPath2 isDirectory:&isDir]) if(![fileManager createDirectoryAtPath:userPath2 withIntermediateDirectories:YES attributes:nil error:NULL]) NSLog(@"Error: Create folder failed %@",userPath2);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    相关资源
    最近更新 更多