-1

I have one created one folder called "MYFOLDER" inside my folder in have one pdf file test.pdf.

I have one button named browse and the textfield. As soon as I click on the browse button I need to navigate through the folders and select the test.pdf file (Like GMAIL Attachment). After selecting particular file I need to set the file path in the text field.

How to do that?

Thanks in advance.

alain.janinm
  • 19,951
  • 10
  • 65
  • 112
sachi
  • 2,122
  • 7
  • 30
  • 46

4 Answers4

1

why not codes?

i appreciated NSFileManager.

    NSFileManager *manager = [NSFileManager defaultManager];
    NSArray *fileList = [manager directoryContentsAtPath:@"/MYFOLDER"];
    NSArray *pdfList = [list filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF ENDSWITH '.pdf'"]];
    NSLog(@"%@", pdfList);
bitmapdata.com
  • 9,572
  • 5
  • 35
  • 43
  • if i know the folder i can use like what you have said. If i dont know how can i navigate multiple folders. – sachi Apr 02 '12 at 06:36
  • I am getting error: 'NSPredicatepredicateWithFormat' undeclared (first use in this function). i don't know why it is coming. @bitmapdata – sachi Apr 02 '12 at 07:03
  • oops, sorry. i forgot about the spacing [NSPredicate predicateWithFormat: i've been corrected codes.. – bitmapdata.com Apr 02 '12 at 07:16
1

Use enumeratorAtPath:

Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified path.

  • (NSDirectoryEnumerator *)enumeratorAtPath:(NSString *)path Parameters

path

The path of the directory to enumerate.

Return Value

An NSDirectoryEnumerator object that enumerates the contents of the directory at path.

If path is a filename, the method returns an enumerator object that enumerates no files—the first call to nextObject will return nil.

Community
  • 1
  • 1
Alex Terente
  • 12,006
  • 5
  • 51
  • 71
0

Maybe this will help you

[[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf";];
Malek_Jundi
  • 6,140
  • 2
  • 27
  • 36
Mangesh
  • 2,257
  • 4
  • 24
  • 51
0

Then you need to list the files and folders in the folder, and keep on browsing.

    NSError *error;
    NSString *homeDirectory = NSHomeDirectory();
    NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:homeDirectory error:&error];

    for(int i = 0; i < [dirContents count]; i++){
         //Here you can browse dirContents
         NSString *fileName = [dirContents objectAtIndex:i];
    }
Jorge Aguirre
  • 2,787
  • 3
  • 20
  • 27