Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get All paths for files in Documents directory?

I usually get paths by using NSBundle.

But, NSBundle does not contain Documents folder.

How to get All paths(or names) for files in Documents directory?

like image 732
ChangUZ Avatar asked Sep 16 '11 05:09

ChangUZ


People also ask

How do I find the path to a file?

Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).

How to find a file directory in Windows?

Search File Explorer: Open File Explorer from the taskbar or right-click on the Start menu, choose File Explorer, then select a location from the left pane to search or browse. For example, select This PC to look in all devices and drives on your computer, or select Documents to look only for files stored there.

What is a folder path?

(Alternate definition: A directory is a folder.) Path: This term is descriptive in that it represents a type of "road map" to a specific file or directory. (Alternate definition: A path is a list, beginning with a drive letter, that tells which folders to open so that you can find a file or another folder.)


1 Answers

This will give u the paths for all files under documents directory

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory  error:nil];

    NSLog(@"files array %@", filePathsArray);

You can get the path for each object in filePathsArray by using the below code

NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[filePathsArray objectAtIndex:0]]; 
like image 116
sElanthiraiyan Avatar answered Nov 09 '22 16:11

sElanthiraiyan