I want to make program, that will ask which file's name to rename.
When I write this code:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
NSString *filename;
NSFileManager *changer;
NSLog(@"Type which file you want to rename");
scanf("%i",&filename);
changer = [NSFileManager defaultManager];
if([changer moveItemAtPath: filename toPath: @"go" error:NULL]==NO)
{ NSLog(@"Cant rename"); return 1; }
}
return 0;
}
I get this error:
2012-03-21 15:30:34.088 ChangeName[1091:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSFileManager moveItemAtPath:toPath:error:]: source path is nil'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff9561a286 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8db76d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff9561a0ba +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff9561a044 +[NSException raise:format:] + 116
4 Foundation 0x00007fff93148d30 -[NSFileManager moveItemAtPath:toPath:error:] + 107
5 ChangeName 0x0000000100000e05 main + 197
6 ChangeName 0x0000000100000d34 start + 52
7 ??? 0x0000000000000001 0x0 + 1
)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
Current language: auto; currently objective-c
(gdb)
When I write this code:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
NSString *filename;
NSFileManager *changer;
NSLog(@"Type which file you want to rename");
scanf("%i",&filename);
changer = [NSFileManager defaultManager];
if([changer moveItemAtPath: filename toPath: @"go" error:NULL]==NO)
{ NSLog(@"Cant rename"); return 1; }
}
return 0;
}
I get this error:
2012-03-21 15:30:34.088 ChangeName[1091:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSFileManager moveItemAtPath:toPath:error:]: source path is nil'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff9561a286 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8db76d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff9561a0ba +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff9561a044 +[NSException raise:format:] + 116
4 Foundation 0x00007fff93148d30 -[NSFileManager moveItemAtPath:toPath:error:] + 107
5 ChangeName 0x0000000100000e05 main + 197
6 ChangeName 0x0000000100000d34 start + 52
7 ??? 0x0000000000000001 0x0 + 1
)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
Current language: auto; currently objective-c
(gdb)