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

mathcolo

macrumors 6502a
Original poster
Sep 14, 2008
860
16
Boston
Hello... A small question for today: I am making a little test application that takes the directory contents at a certain path and then deletes the file that was changed most recently.

This is what I have so far:

Code:
NSString *thepath = [self path]; //path is /Users/mathcolo/hello/
	NSFileManager *fm = [NSFileManager defaultManager];
	NSArray *fileContents = [fm directoryContentsAtPath:thepath];
	NSString *filepath;
	int i;

	for (i=0; i<[fileContents count]; i++) {

//Do something with the files here or something
}
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
So what specifically is the question? How to delete a file or how to get its modified date?
 

mathcolo

macrumors 6502a
Original poster
Sep 14, 2008
860
16
Boston
So what specifically is the question? How to delete a file or how to get its modified date?

Basically I'm trying to figure out how to make it so when I click a button, the file that has been most recently changed is deleted.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
Basically I'm trying to figure out how to make it so when I click a button, the file that has been most recently changed is deleted.

Well, you would have to find out when each file is modified, then you would iterate through the files and see which one was the last to be modified, and then you would delete the file.

And for the button: You would add the button to a view in interface builder, associate an action with it, and write an action method that does the deleting.
 

mathcolo

macrumors 6502a
Original poster
Sep 14, 2008
860
16
Boston
Well, you would have to find out when each file is modified, then you would iterate through the files and see which one was the last to be modified, and then you would delete the file.

And for the button: You would add the button to a view in interface builder, associate an action with it, and write an action method that does the deleting.

Ok, sounds like that would work. I guess I should be able to use attributesOfFileSystemForPath:error: and do a loop for each file.

Thanks gnasher729.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.