Questions tagged [nsfilemanager]

The NSFileManager class enables you to perform various generic file-system operations and insulates an application from the underlying file system.

An apple class reference.

A simple file handling

//Gives you document folder detail

    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager setDelegate:self];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSArray *newfilelist=[fileManager contentsOfDirectoryAtPath:documentsDirectory error:&error ];

//gives your file is file or directory

NSString *path = @"/Users";
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSLog(@"fileManager=%@", fileManager);
    BOOL bDirectory;
    BOOL bExists = [fileManager fileExistsAtPath:path isDirectory:&bDirectory];
    NSLog(@"%@: bExists=%d bDirectory=%d", path, bExists, bDirectory);
1453 questions
-1
votes
1 answer

How to save a video to a URL in Swift Playgrounds

I'm trying to instantiate a PHLivePhoto but whenever I try to save the video that constitutes the live photo I can't get it to work. Here's a little code snippet I wrote that handles exporting the video: public func exportFilteredVideo(to outputURL:…
Harish
  • 1,374
  • 17
  • 39
-1
votes
1 answer

What is the best way to upload a file/photo from an iOS device?

Here's the scenario: My application features an account system, wherein users may login/logout the app, thus enabling other users to login as well using the same iOS device. Upon successful login, it downloads the files (like pdf, ppt, and etc) from…
iOSNewbie
  • 85
  • 1
  • 9
-1
votes
1 answer

FileManager.urls returning error

I recently converted my project to Swift 3 and for the most part, it seems okay. However, I receive an error related to FileManager that says: "Use of instance member 'urls' on type 'FileManager'; did you mean to use a value of type 'FileManager'…
Jake
  • 801
  • 1
  • 6
  • 10
-1
votes
1 answer

Rewrite or delete existing .png file in IOS swift apllication

I would like to add the text on my .png image which exist in my swift application and REPLACE my old image with this edited image. But when I am trying to remove old image I am getting the error message : Error : Error…
Andrey
  • 3
  • 3
-1
votes
1 answer

Why is NSFileManager not working properly?

My app downloads files from the internet and stores them using NSFileManager everything seems to be working until I rerun the app using xCode (I can't use the files, remove them-....) But if I didn't rerun it with xCode and used it normally on my…
Raffi
  • 699
  • 1
  • 8
  • 19
-1
votes
2 answers

How to get NSURL of removable Volumes on OS X and notification when it mounts?

I need to detect when an USB drive e.g. Office23, is mounted in OS X and also search for a file eg. jan.txt inside the drive and copy it to app bundle. I am using following method to find if volume is mounted or not: NSFileManager *fileManager =…
Napier
  • 105
  • 8
-1
votes
1 answer

how to delete file from my iphone 's app memory. from file manager ios swift

i am storing my data in file manager in my app. now i want to delete specific data by code so how can i do this? here is my code which i used for store data var localURL : String init() { let urls =…
Govind
  • 411
  • 1
  • 5
  • 11
-1
votes
1 answer

Archiving, unarchiving and cleaning objects in cache with Swift

I have problems in handling the persistence of some classes in the cache. This is the code I tried and that does not work at all either recovering the archived data or deleting it: func cacheDirectoryURL()->NSURL?{ let…
-1
votes
2 answers

Saving Image to iOS documents directory

I've been following this answer from SO Stack Overflow Answer Problem is the file path does not return any data that should be saved to Documents folder in the app file structure. I save the file path to CoreData, and this works fine, however, when…
noobsmcgoobs
  • 2,716
  • 5
  • 32
  • 52
-1
votes
1 answer

How to get the sizes of all files in mac in objective c

I am having a cocoa mac app for OSX. In my app, I want to get the sizes of all the files in my mac programmatically in objective c. Here is the I have searched a lot but unable to find proper solution. I am finding the system size with the…
Manthan
  • 3,856
  • 1
  • 27
  • 58
-1
votes
1 answer

check Filename is exist by prefix in Swift

I want to check whether my filename with just prefix is exist or not in Swift. E.g My file name is like Companies_12344 So after _ values are dynamic but "Companies_" is static. How can i do that? My code below For split func splitFilename(str:…
dhaval shah
  • 4,499
  • 10
  • 29
  • 42
-1
votes
1 answer

File path keep changing

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentDir = [documentPaths objectAtIndex:0]; self.databasePath = [documentDir…
Prajeet Shrestha
  • 7,978
  • 3
  • 34
  • 63
-1
votes
1 answer

Error checking for subdirectory of Documents directory in IOS

My app needs to create a subdirectory of the Documents directory. The code below returns the directory URL. First time through it creates the directory, but fails next time because fileExistsAtPath: claims the directory still doesn't exist. I know…
easiwriter
  • 73
  • 1
  • 8
-1
votes
1 answer

as I can move all files from one directory to another directory in Objective-C?

as I can move all files from one directory to another directory? I have my code so to move them individually, but I can not move them all. NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,…
-1
votes
1 answer

Loading large images from disk in ios app

Currently I am downloading images of size 8 mb and storing them in the document path inside the app. During testing process, I noticed that the memory use increases a lot when fetching the images from the document and show them in the collection…
Moeit
  • 67
  • 1
  • 7