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
0
votes
3 answers

Issue in showing already created folder

I have been successful in creating folder in "Documents" folder in iPhone simulator. NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths…
Krunal
  • 1,318
  • 1
  • 13
  • 31
0
votes
1 answer

Read file permissions in Cocoa

I am trying to read file permissions in Cocoa of a file having rw-r--r-- (hence 0644). The code I am using is the following: NSUInteger permissions; permissions=[[fileManager attributesOfItemAtPath:file error:nil]…
Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89
0
votes
1 answer

Write image data in dispatch_async

I'm having a problem when I try to save an UIImage as a PNG file by using GCD. Here's what am I writing : NSString *fileName = [[NSString stringWithFormat:@"%@.png",url] substringFromIndex:5]; dispatch_queue_t queue =…
Pierre
  • 10,593
  • 5
  • 50
  • 80
0
votes
2 answers

NSFileManager Cant create file

I have this code. This code won't create a file in the Document directory and i have no idea why. Can anyone see what I'm missing. "data" dictionary has what i need in it but when it comes to writeToFile: it's not happening because there is no file…
Spire
  • 1,055
  • 2
  • 17
  • 47
-1
votes
1 answer

iOS, Delete all data saved to device by app using NSFileManager

I want my app to delete all the information it has saved to the device, and i was told you do this using the NSFile Manager, so i was wondering what the code was to do this?
Oli
  • 117
  • 1
  • 10
-1
votes
1 answer

Swift relativePath property that FileManager.default.enumerator outputs is full path

I want to get relative paths, but I get full paths in the following code. Xcode 14.3 let homePath = NSHomeDirectory() let homeURL = URL(fileURLWithPath: ".", relativeTo: URL(fileURLWithPath: homePath)) guard let fileEnumeratorIncludingSubFolder =…
Takakiri
  • 33
  • 2
  • 6
-1
votes
1 answer

Has the behavior of copyItemAtPath changed under Ventura? Returning "file doesn't exist"

My app creates a working file in the Application Support folder at launch, and subsequently saves that file in a user preferred folder (specified in preferences as a path). The save code is very simple: - (void) saveFile: (NSString *) path { …
johnpurlia
  • 113
  • 6
-1
votes
1 answer

How do i save video to new directory in ios?

I'm working with filemanager. So far I'm able to initialize my directory but when I try to save data there, the error i get is "error: Cannot create file".There seems to be an issue with the way I'm creating my path because when I use a temporary…
codechef
  • 55
  • 1
  • 8
-1
votes
2 answers

Different path URL for FileManager everytime I open the app

I want to create one folder in the fileManager root path, but before creating it, I want to check that the folder exist or not, and if not, I will create, otherwise will leave it here are the function that I use public func isDirectoryExist(path:…
-1
votes
1 answer

While loop with NSFileManager directory enumerator not running

I am seeking help to understand why a tutorial I am following is not working for me. I am running macOS 12.3.1, Xcode 13.3.1. The project is in Objective-C and using XIB. This is a view-based NSTableView, using a folder of PNGs stored on my SSD for…
NotationMaster
  • 390
  • 3
  • 17
-1
votes
2 answers

Can not write data to file in iOS Swift

I manually created a file amutha.txt in the documents folder. I tried to write data to that file. code which I used is let string="Amuthapriya" try string.write(to:fileName, atomically: true, encoding: String.Encoding.utf8) This is executed…
Priya Sri
  • 145
  • 13
-1
votes
1 answer

tmp video file accessible to AVPlayer on simulator but not device

My app edits a video and exports the edited version. I have the app running with no problems in the simulators, but when I try to preview the edited version of the video on a device I am not able to. I've tried all the de-bugging I could think of…
TJMac
  • 129
  • 1
  • 12
-1
votes
1 answer

Is there a way to prevent NSFilemanger from exporting data and creating a folder?

Whenever the user exports data (it is a JSON format) it creates a folder named "Documents." And does not directly export the file and it does this for both my JSON export and CSV. I have tried changing the fileManager settings but nothing seems to…
117MasterChief96
  • 548
  • 1
  • 5
  • 16
-1
votes
1 answer

Saving image to documents directory with overwrite

I am capturing a photo with the device camera and saving it to the Documents directory with a specific filename. However, if a file of the same name already exists then the file is not saved. How can I simply overwrite a file of the same name, or if…
-1
votes
1 answer

how to use fileManager.unmountVolume in swift

im trying to eject/unmount a usb drive in swift i think i have to use fileManager.unmountVolume let urlString = "/Volumes/UNTITLED/".addingPercentEncoding(withAllowedCharacters: .urlUserAllowed) let url = URL(string:…
jeana
  • 11
  • 2