Skip to content
Cocoa Maker 5 - File Management episode artwork

Mar 20, 2010

Cocoa Maker 5 - File Management

from Cocoa Maker Hosted by Mr. Gecko

James (MrGeckosMedia.com), joined by, Noah (RockntheSweater.com), and Karl, explains how file managing works in c and cocoa. 7:49 Example code from episode. Files C Example #import <Foundation/Foundation.h> BOOL file_exist(const char *fileName) { FILE *file = fopen(fileName, "r"); if (file) { fclose(file); return YES; } return NO; } int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; const char *ourFile = [[@"~/Desktop/file.txt" stringByExpandingTildeInPath] UTF8String]; FILE *file; if (!file_exist(ourFile)) { file = fopen(ourFile, "w"); time_t currTime = time(NULL); fprintf(file, "%s: We just made this file.\n", ctime(&currTime)); } else { file = fopen(ourFile, "a"); } time_t currTime = time(NULL); fprintf(file, "%s: Here is a new line in this file.\n", ctime(&currTime)); fclose(file); [pool drain]; return 0; } Files Cocoa Exmaple #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSFileManager *manager = [NSFileManager defaultManager]; NSString *ourFile = [@"~/Desktop/file.txt" stringByExpandingTildeInPath]; NSFileHandle *file; if (![manager fileExistsAtPath:ourFile]) { [manager createFileAtPath:ourFile contents:nil attributes:nil]; file = [NSFileHandle fileHandleForWritingAtPath:ourFile]; [file writeData:[[NSString stringWithFormat:@"%@: Here is a new file.\n", [NSDate date]] dataUsingEncoding:NSUTF8StringEncoding]]; } else { file = [NSFileHandle fileHandleForWritingAtPath:ourFile]; [file seekToEndOfFile]; } [file writeData:[[NSString stringWithFormat:@"%@: Here is a new line.\n", [NSDate date]] dataUsingEncoding:NSUTF8StringEncoding]]; [file closeFile]; [pool drain]; return 0; } Keynote used in this Episode Keynote in PDF Format

Episode details come from the podcast's RSS feed.

Embed this episode

Ready to play

Cocoa Maker 5 - File Management

No transcript yet.

Requests help us decide what to transcribe next.

AI, Government, and the Future Corner Alliance Welcome to AI, Government, and the Future, a podcast by Corner Alliance. We explore the intersection of artificial intelligence, government, and the future. Join us as we dive into the latest AI advancements, government policies, and innovative strategies to shape the future of our society. Whether you're a policy maker, venture capitalist, academic, or industry leader, this podcast will provide valuable insights and thought-provoking discussions to help you navigate the evolving landscape of AI and its impact on government. Tune in to AI, Government, and the Future to stay ahead in this transformative era. The Bootloader Paul Cutler and Tod Kurt A monthly podcast loading you up with news, project updates and product talk from the CircuitPython and maker communities. Hosted by Tod Kurt and Paul Cutler. Hack Learning Mark Barnes Learn quick and easy ways to improve education, leadership, and parenting: How to replace traditional homework; how to improve leadership; how to integrate new technology; how to assess for learning; how to eliminate useless meetings; how to engage even the most reluctant learners; how to inspire a lifelong love of reading; how to combine writing with the maker space; how to take learning mobile; how to improve social media strategies. Teacher/author/global influencer Mark Barnes, creator of the Bestselling Hack Learning Book Series, explains precisely what's wrong with education and what you can do about it, tomorrow; because you don't need a 5-year plan. Learn more at http://10publications.com.

Frequently asked questions

When was this Cocoa Maker episode published?

This episode was published on March 20, 2010.

Can I download this Cocoa Maker episode?

Yes. Use the download control on the episode player to save the publisher-provided media file.