I stored a pdf file using NSData in my application memory. Now i want that file name each time to add those names into an array. How can i get the pdf file's name from my application memory to use in my app.
Asked
Active
Viewed 566 times
0
-
1Application memory or application's Documents folder (disk) ? Would be pretty bad to just have a big NSData file just ocuppying RAM, plus it gets lost when the app is restarted. – Tudor Nov 04 '11 at 09:26
-
Its in application documents folder. – Christo Joel Nov 04 '11 at 09:28
-
This might help you out: http://stackoverflow.com/questions/6093389/applications-document-folder-in-iphone – Niranjan Nov 04 '11 at 09:33
3 Answers
2
You can't since you only stored the file as a data object and not it's file name.
You could try to read the PDF meta data to check if there's a file name.

rckoenes
- 69,092
- 8
- 134
- 166
-
-
Is this for the file stored in application memory's documents folder? – Christo Joel Nov 04 '11 at 09:32
-
If your file is stored in the documents direct that you know the filename, because you saved it there. So when you load it in the NSData object you us the path and file. You will need to save the filename, in an array, as wel not just the data object. – rckoenes Nov 04 '11 at 09:38
1
The answer here should help:
Getting a list of files in the Resources folder - iOS
It will list all the files in the Documents dir.
-
Or this, for other file manipulations: http://www.ios-developer.net/iphone-ipad-programmer/development/file-saving-and-loading/using-the-document-directory-to-store-files – Tudor Nov 04 '11 at 09:32
-
Is this for the file stored in application memory's documents folder? – Christo Joel Nov 04 '11 at 09:33
-
0
I suppose by "Application Memory" you mean one of the App's directories like Documents or Library.
You can just use NSFileManager to access the directory and get a list of all files, like if you stored it in your app's library folder:
NSArray* directoryPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUSerDomainMask, YES];
NSString* path = [directoryPaths objectAtIndex:0];
NSArray* files = [NSFileManager defaultManager] contentsOfDirectoryAtPath:path];
On top of that you can use a filter predicate to only get files with a .pdf ending.

TheEye
- 9,280
- 2
- 42
- 58