<p>What would be the easiest way to separate the directory name from the file name when dealing with <code>SaveFileDialog.FileName</code> in C#?</p>

[{'answer_id': 16313, 'author': 'rjzii', 'author_id': 1185, 'author_profile': 'https://Stackoverflow.com/users/1185', 'pm_score': 0, 'selected': False, 'text': '<p>Since the forward slash is not allowed in the filename, one simple way is to divide the SaveFileDialog.Filename using String.LastIndexOf; for example:</p>\n\n<pre><code>string filename = dialog.Filename;\nstring path = filename.Substring(0, filename.LastIndexOf("\\"));\nstring file = filename.Substring(filename.LastIndexOf("\\") + 1);\n</code></pre>\n'}, {'answer_id': 16315, 'author': 'Jay Mooney', 'author_id': 733, 'author_profile': 'https://Stackoverflow.com/users/733', 'pm_score': 1, 'selected': False, 'text': '<p>The Path object in <code>System.IO</code> parses it pretty nicely.</p>\n'}, {'answer_id': 16316, 'author': 'Jake Pearson', 'author_id': 632, 'author_profile': 'https://Stackoverflow.com/users/632', 'pm_score': 2, 'selected': False, 'text': '<p>You could construct a FileInfo object.  It has a Name, FullName, and DirectoryName property.</p>\n\n<pre><code>var file = new FileInfo(saveFileDialog.FileName);\nConsole.WriteLine("File is: " + file.Name);\nConsole.WriteLine("Directory is: " + file.DirectoryName);\n</code></pre>\n'}, {'answer_id': 16318, 'author': 'Adam Wright', 'author_id': 1200, 'author_profile': 'https://Stackoverflow.com/users/1200', 'pm_score': 5, 'selected': True, 'text': '<p>Use:</p>\n\n<pre><code>System.IO.Path.GetDirectoryName(saveDialog.FileName)\n</code></pre>\n\n<p>(and the corresponding <code>System.IO.Path.GetFileName</code>). The Path class is really rather useful.</p>\n'}]
['https://Stackoverflow.com/questions/16306', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/41/']