//NSFileManager *fm = [NSFileManager defaultManager];
// NSString *dirName = @"testdir";
//NSString *path = [fm currentDirectoryPath];
//NSLog(@"Current directory path is %@",path);
//create a new directory
//if([fm createDirectoryAtPath:dirName withIntermediateDirectories:NO attributes:nil error:nil] == NO){
// NSLog(@"couldn't create directory");
// return 1;
//}
//rename the directory
//if([fm moveItemAtPath:dirName toPath:@"newdir" error:nil] == NO){
// NSLog(@"directory rename failed");
// return 2;
//}
//change directory into the new directory
//if([fm changeCurrentDirectoryPath:@"newdir"] == NO){
// NSLog(@"change directory failed!");
// return 3;
//}
//path = [fm currentDirectoryPath];
//NSLog(@"%@",path);
/*
NSFileManager *fm = [NSFileManager defaultManager];
NSDirectoryEnumerator *dirEnum;
NSArray *dirArray;
NSString *path = [fm currentDirectoryPath];
//Enumerate the directory
dirEnum = [fm enumeratorAtPath:path];
NSLog(@"contents of %@",path);
BOOL flag;
while ((path = [dirEnum nextObject]) != nil) {
NSLog(@"%@",path);
[fm fileExistsAtPath:path isDirectory:&flag];
if(flag == YES)
[dirEnum skipDescendants];
}
//Another way to enumerate a directory
dirArray = [fm contentsOfDirectoryAtPath:[fm currentDirectoryPath] error:nil];
NSLog(@"contents using directoryContentsAtPath: ");
for(path in dirArray)
NSLog(@"%@",path);
*/
NSString *fName = @"test.txt";
NSFileManager *fm;
NSString *path,*tempdir,*extension,*homedir,*fullpath;
//NSString *upath = @"~";
NSArray *components;
fm = [NSFileManager defaultManager];
//get the temporary working directory
tempdir = NSTemporaryDirectory();
NSLog(@"temporary directory is %@",tempdir);
//extact the base directory from current directory
path = [fm currentDirectoryPath];
NSLog(@"base dir is %@",[path lastPathComponent]);
//create a fullpath to the file fName in current directory
fullpath = [path stringByAppendingPathComponent:fName];
NSLog(@"fullpath to %@ is %@",fName,fullpath);
//get the file name extension
extension = [fullpath pathExtension];
NSLog(@"extension for %@ is %@",fullpath,extension);
//get the user's home directory
homedir = NSHomeDirectory();
NSLog(@"your home directory is %@",homedir);
//divide a path into its components
components = [homedir componentsSeparatedByString:@"/"];
NSLog(@"%@",components);
//standardize a path
NSLog(@"%@ => %@",@"../",[@"../" stringByStandardizingPath]);