我正在尝试使用NSFileManager
copyItemAtURL:toURL:error:
将 UNIX 可执行文件(命令行程序)从一个目录移动到另一个目录,但我总是收到一条错误消息,指出 URL 类型不受支持。我认为这是因为文件上没有扩展名,它被视为一个目录,但我不确定。是否可以使用 移动这种类型的文件NSFileManager
?
编辑:这是我的代码
#define SAVE_DIR [@"~/Library/Prog" stringByExpandingTildeInPath]
#define PROG_PATH [SAVE_DIR stringByAppendingString:@"/ProgCom"]
#define RESOURCES [[NSBundle mainBundle] resourcePath]
#define LOCAL_PROG [RESOURCES stringByAppendingString:@"/ProgCom"]
-(void)moveProg
{
NSError *error = nil;
NSURL *fromURL = [NSURL URLWithString:LOCAL_PROG];
NSURL *toURL = [NSURL URLWithString:PROG_PATH];
NSLog(@"%@", [fromURL path]);
NSLog(@"%@", [toURL path]);
if ([fMan fileExistsAtPath:[fromURL path]]) {
[fMan copyItemAtURL:fromURL
toURL:toURL
error:&error];
if (error)
[NSApp presentError:error];
}
}
我收到的错误:
The file couldn't be opened because the specified URL type isn't supported.
最后记录了什么:
fromURL = /Users/Nick/Library/Developer/Xcode/DerivedData/Prog-dpnblqaraeuecyadjgizbinfrtcm/Build/Products/Debug/Prog.app/Contents/Resources/ProgCom
toURL = /Users/Nick/Library/Prog/ProgCom