Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

duny

macrumors newbie
Original poster
Sep 21, 2008
26
0
H-Town
Can someone show me the code for the
.h and .m ViewControl to obtain the files in a directory.
 

GregInAZ

macrumors newbie
Aug 2, 2008
23
0
Look at directoryContentsAtPath, which is part of NSFileManager. This will return an array.
 

duny

macrumors newbie
Original poster
Sep 21, 2008
26
0
H-Town
K I read it as always, but i am still lost ing the sause, i read the NSDirectoryEnumerator, it's exactly what i am looking for, I follow the text but nothing, it says i need NSFileManager.h would that be the same as i ManagerViewController.h i have created. I hav a Table View Set up in one of my .XIB files, i want to be able to view the directory.

No matter what i play with i still get errors. Can some one just show me barney style how this is done.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Code:
	NSDirectoryEnumerator*	e = [[NSFileManager defaultManager] enumeratorAtPath:MMDocumentsFolder()];
	
	// Ignore any files except XYZ.jpg
	for (NSString*	file in e)
	{
		if (NSOrderedSame == [[file pathExtension] caseInsensitiveCompare:@"jpg"])
		{
			// Do something with file.jpg
		}
		else
		if ([[[e fileAttributes] fileType] isEqualToString:NSFileTypeDirectory])
		{
			// Ignore any subdirectories
			[e skipDescendents];
		}
	}
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
It's source code. It goes in the method that you're writing that wants to scan a directory. Nothing needs to go in the .h file.
 

duny

macrumors newbie
Original poster
Sep 21, 2008
26
0
H-Town
Here is what i got.

untitled.m
Code:
- (void)viewWillAppear{
	NSString *file;
	NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent:  @"Documents"];
	NSDirectoryEnumerator *dirEnum =
    [[NSFileManager defaultManager] enumeratorAtPath:docsDir];
	
	while (file = [dirEnum nextObject]) {
		if ([[file pathExtension] isEqualToString: @"doc"]) {
			[self scanDocument: [docsDir stringByAppendingPathComponent:file]];
		}
	}
}
@end


And Untitled.h
Code:
@interface ManageViewController : UITableViewController {
		
}

@end

The error i get when i compile is
warning "ManageViewCpntroller" may not reposnd to '-scanDocument'
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Of course it may not respond. You didn't implement any such method.

Let me suggest that you spend some time doing tutorials. Perhaps buy a Cocoa book like the Hillegas book and run through the examples in that book or an iPhone dev book when they become available.
 

duny

macrumors newbie
Original poster
Sep 21, 2008
26
0
H-Town
Cant you just help me out. The iphone dev book doesn't come out till January.
 

robotspacer

macrumors member
Jun 25, 2007
46
0
You're calling a method that you haven't created yet, so helping you out would basically amount to writing your app for you!

I think you definitely need to spend some time learning the basics of Objective-C and Cocoa. The aforementioned book by Aaron Hillegass is a great place to start: http://www.amazon.com/Cocoa-Programming-Mac-OS-3rd/dp/0321503619/

So is Cocoa Dev Central:
http://cocoadevcentral.com

Both of these deal with specifically Mac software development, so not everything will apply, but the basics (and even some of the more complex stuff) are very very similar.

I also highly recommend looking at the various sample projects Apple has posted at http://developer.apple.com
 

firewood

macrumors G3
Jul 29, 2003
8,141
1,384
Silicon Valley
Hillegass's new book is already out and will help you understand some of the basic concepts you are missing. Maybe a C primer if that's over your head. Also, read as much of the Cocoa ond Objective C documentation on the Apple site as you can. Otherwise it's too much like explaining how to cook fettucini to someone who hasn't figured out how to boil water yet.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.