nsfilemanager

How to obtain the size of a Application Directory in iPhone?

橙三吉。 提交于 2019-12-04 23:45:49
问题 (NSString *) getApplicationUsage{ double directorySizeInBytes = 0.0f; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSUserDomainMask, YES); NSString *pathStr = [paths objectAtIndex:0]; pathStr = [pathStr stringByDeletingLastPathComponent]; //REMOVE THE LAST PATH COMPONENT i.e /Applications NSDirectoryEnumerator *enumrator = [[NSFileManager defaultManager] enumeratorAtPath:pathStr]; for (NSString *itemPath in enumrator) { itemPath = [pathStr

Check if file exists at URL instead of path

一个人想着一个人 提交于 2019-12-04 22:11:39
How can I check if a file exists at a URL (instead of a path), in order to set a pre-populated default store into the iPhone Simulator: NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Food.sqlite"]; /* Set up the store. For the sake of illustration, provide a pre-populated default store. */ NSFileManager *fileManager = [NSFileManager defaultManager]; // If the expected store doesn't exist, copy the default store. if (![fileManager fileExistsAtPath:storePath]) { NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"Food" ofType:@"sqlite"];

How to save image or video from UIPickerViewController to document directory?

我与影子孤独终老i 提交于 2019-12-04 16:59:27
Handle selected image or video: func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { print("ok") if let image = info[UIImagePickerControllerOriginalImage] as? UIImage { //what to do to save that image } else { //how to get the video and save } } Save it to the document directory: let path = try! NSFileManager.defaultManager().URLForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomain: NSSearchPathDomainMask.UserDomainMask, appropriateForURL: nil, create: false) let newPath = path.URLByAppendingPathComponent("image.jpg")

How to find file types in objective c

我只是一个虾纸丫 提交于 2019-12-04 16:10:44
I have done a lot of research on this and haven't found anything useful. I want am making a simple program in objective c for personal use that opens files and gives information about them. The only problem i have encountered is that i cannot find the file of a file i am opening. Without simply looking at the extension, is there a way to find the full file format of a file in objective c? If possible, i would also like to be able to save that file in a different format. Information on this subject is also important for this application. Help will be greatly appreciated. Mac OS X has type

iOS - Get sum of filesize in directory

僤鯓⒐⒋嵵緔 提交于 2019-12-04 13:16:25
问题 I have the following code I use to cache photos I load off Flickr in the device's memory: NSURL *urlForPhoto = [FlickrFetcher urlForPhoto:self.photo format:FlickrPhotoFormatLarge]; NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *imagePath = [rootPath stringByAppendingString:[self.photo objectForKey:FLICKR_PHOTO_ID]]; NSData *dataForPhoto; NSError *error = nil; if ([[NSFileManager defaultManager] fileExistsAtPath

How to get the list of directores in NSDocumentDirectory?

六眼飞鱼酱① 提交于 2019-12-04 12:38:06
问题 I have created some directories in NSDocumentDirectory as if (![tbxCreateFolder.text isEqualToString:@""]) { NSArray *arrPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectoryStr = [arrPaths objectAtIndex:0]; // Get documents folder NSString *dataPath = [documentsDirectoryStr stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@",tbxCreateFolder.text]]; if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]){

iPhone: NSFilemanager fileExistsAtPath:isDirectory: not working properly?

纵然是瞬间 提交于 2019-12-04 11:35:23
问题 I'm working on an app for jailbroken iPhones. I'm trying to get only the directories of an folder. so I'm doing this: NSArray *contentOfFolder = [[NSFileManager defaultManager] directoryContentsAtPath:path]; NSLog(@"contentOfFolder: %@", contentOfFolder); directoriesOfFolder = [[NSMutableArray alloc] initWithCapacity:100]; for (NSString *aPath in contentOfFolder) { NSLog(@"apath: %@", aPath); BOOL isDir; if ([[NSFileManager defaultManager] fileExistsAtPath:aPath isDirectory:&isDir] &&isDir) {

Get resource URL from project specific path

假装没事ソ 提交于 2019-12-04 10:05:51
问题 I need to retrieve the URL of a resource contained in my Xcode project through a path that begins in the project's directory (aka mainBundle) So if my specified path if ./snd/archer/acknowledge1.wav, I need to create a URL from that. I know I can use NSURL(fileURLWithPath:) for system directories, but I don't know how to do this directly from the bundle. 回答1: You would use one of the bundle resourse URL methods [[NSBundle mainBundle] URLForResource:@"acknowledge1" withExtension:@"wav"

NSFileManager & NSFilePosixPermissions

人盡茶涼 提交于 2019-12-04 07:42:47
I want to use the octal permissions (used for chmod) for NSFilePosixPermissions. Here is what I did now: NSFileManager *manager = [NSFileManager defaultManager]; NSDictionary *attributes; [attributes setValue:[NSString stringWithFormat:@"%d", 0777] forKey:@"NSFilePosixPermissions"]; // chmod permissions 777 [manager setAttributes:attributes ofItemAtPath:@"/Users/lucky/Desktop/script" error:nil]; I get no error, but when I check the result with "ls -o" the permission are't -rwxrwxrwx. What's wrong? Thanks for help. gcbrueckmann First, NSFilePosixPermissions is the name of a constant. Its value

iOS: How to delete all existing files with specific extension from the documents dir?

旧时模样 提交于 2019-12-04 05:46:40
When I update my iOS app, I want to delete any existing sqlite databases in the Documents directory. Right now, on an application update, I copy the database from the bundle to the documents directory and name it by appending the bundle version. So, on the update, I also want to delete any old versions that might exist. I just want to be able to delete all sqlite files, without having to loop through and look for ones from previous versions. Is there any way to wildcard the removeFileAtPath: method? memmons So, you'd like to delete all *.sqlite files? There is no way to avoid looping, but you