Skip to content

Instantly share code, notes, and snippets.

@liufsd
Last active April 4, 2017 11:02
Show Gist options
  • Save liufsd/c1e278f8a92f51b2090a77d27942f3bc to your computer and use it in GitHub Desktop.
Save liufsd/c1e278f8a92f51b2090a77d27942f3bc to your computer and use it in GitHub Desktop.
//
// DirectoryUtils.h
// PhotoCloud
//
// Created by liupeng on 14/11/2016.
// Copyright © 2016 liupeng. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface DirectoryUtils : NSObject
+(NSString* )RealHomeDirectory;
+(NSURL* )picturesDirectory;
+(NSURL* )downloadsDirectory;
+(NSURL* )moviesDirectory;
+(NSURL* )musicDirectory;
@end
//
// DirectoryUtils.m
// PhotoCloud
//
// Created by liupeng on 14/11/2016.
// Copyright © 2016 liupeng. All rights reserved.
//
#import "DirectoryUtils.h"
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
@implementation DirectoryUtils
+(NSString* ) RealHomeDirectory
{
struct passwd *pw = getpwuid(getuid());
return [NSString stringWithUTF8String:pw->pw_dir];
}
+(NSURL* )picturesDirectory {
return [[NSURL fileURLWithPath:[self RealHomeDirectory]] URLByAppendingPathComponent:@"Pictures"];
}
+(NSURL* )downloadsDirectory {
return [[NSURL fileURLWithPath:[self RealHomeDirectory]] URLByAppendingPathComponent:@"Downloads"];
}
+(NSURL* )moviesDirectory {
return [[NSURL fileURLWithPath:[self RealHomeDirectory]] URLByAppendingPathComponent:@"Movies"];
}
+(NSURL* )musicDirectory {
return [[NSURL fileURLWithPath:[self RealHomeDirectory]] URLByAppendingPathComponent:@"Music"];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment