Matt Legend Gemmell Modesty is Lying

Mac OS X Cocoa and iPhone Development Services available at Instinctive Code.
Mac OS X Cocoa and iPhone Developer for hire

Other Pages

Categories

Posted
10 April 2008 @ 12pm

Categories
Development, Source

Tags
, , , , , , , , , , , ,

FolderSweep source code

Some new source code for you, this time from my esteemed colleague Rainer “RBSplitView” Brockerhoff, in collusion with myself. The code is called FolderSweep, and in a nutshell it shows you how to recursively traverse a folder-hierarchy really quickly (faster than using NSFileManager) and in a controlled way, optionally also memory-mapping the contents of files and providing them to your delegate object.

The code shows how to:

  • Easily set up a FolderSweeper in a given folder (choosing whether to follow symlinks/aliases or not).
  • Approve or reject further processing of files/folders as necessary.
  • Determine whether a given file conforms to a given UTI (Uniform Type Identifier), in this case text.
  • Retrieve the memory-mapped contents of files.
  • Perform text encoding-detection (or sniffing) to determine how to interpret the text file.
  • And quite probably more.

We’ve commented the class and also the demo code quite heavily, so it should be immediately useful. You can always grab the latest version of the code from my public Subversion repository here: http://svn.cocoasourcecode.com/FolderSweep, and Rainer will be putting a zip file of the current version up on his site later today.

If you’re not sure how to access a Subversion repository, just launch Terminal, cd to wherever you want to keep the code, and then type this command:

svn co http://svn.cocoasourcecode.com/FolderSweep

You’ll get a copy of the code in your current working directory.

Send any bug reports or enhancement requests either to Rainer (preferably) or to me. Enjoy!


2 Comments

Aaron
8 May 2008 @ 1pm

Is there any way to get the full path to the files as they are processed, instead of just the filename?


Matt Legend Gemmell
8 May 2008 @ 1pm

Hi Aaron,

Yes, it’s easy. In the sweeper:processFile:named:hasInfo:contents: method, you’re given an FSRef for the file. You can turn that into a path like this:

NSString *path = [sweeper pathForRef:aFileRef];


Leave a Comment

iPhone Development MGTwitterEngine and MGViewAnimation updated