title: How to build a complete and safe file path when I have a directory path, a file name and an extension?
body: <p>Assuming that directoryPath points to the Documents directory of the app:</p>
  
  <pre><code>NSString *fileName = @"demo";
  NSString *extension = @"txt";
  NSString *filePath = [directoryPath stringByAppendingPathComponent:fileName];
  filePath = [filePath stringByAppendingPathExtension:extension];
  </code></pre>
  
  <p>I <em>THINK</em> that this is the way to do it, but I am not sure. Maybe there is an even better one. First I thought maybe I just create the file name with extension like this:</p>
  
  <pre><code>NSString *fileName = [NSString stringWithFormat:@"%@.%@", fileName, extension];
  </code></pre>
  
  <p>And then append it using <code>-stringByAppendingPathComponent:</code> , but I bet this is a bad idea for some reason. Maybe because it hard-codes the dot separator for extensions. They will never change this because it would be dump as hell. But you never know. So...</p>
  
  <p>Did I do it the right way?</p>
  
  <p>Need support for old OS versions.</p>