title: Rename file in Cocoa?
body: <p>How would I rename a file, keeping the file in the same directory?</p>
  
  <p>I have a string containing a full path to a file, and a string containing a the new filename (and no path), for example:</p>
  
  <pre><code>NSString *old_filepath = @"/Volumes/blah/myfilewithrubbishname.avi";
  NSString *new_filename = @"My Correctly Named File.avi";
  </code></pre>
  
  <p>I know about NSFileManager's <a href="http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/movePath:toPath:handler:" rel="noreferrer">movePath:toPath:handler:</a> method, but I cannot workout how to construct the new file's path..</p>
  
  <p>Basically I'm looking for the equivalent to the following Python code:</p>
  
  <pre><code>&gt;&gt;&gt; import os
  &gt;&gt;&gt; old_filepath = "/Volumes/blah/myfilewithrubbishname.avi"
  &gt;&gt;&gt; new_filename = "My Correctly Named File.avi"
  &gt;&gt;&gt; dirname = os.path.split(old_filepath)[0]
  &gt;&gt;&gt; new_filepath = os.path.join(dirname, new_filename)
  &gt;&gt;&gt; print new_filepath
  /Volumes/blah/My Correctly Named File.avi
  &gt;&gt;&gt; os.rename(old_filepath, new_filepath)
  </code></pre>